legacy/createcsvs.py
def main(input_folder, output_folder, dates_file, plots):
    """Turn SVG graphs into CSVs.

    Given an input folder of single plot SVGs convert them into CSV files.

    Args:
        input_folder: Location of SVG files
        output_folder: Location to store the CSVs
        dates_file: Lookup from x axis steps to date
        plots: Boolean flag
            Set to true to create png plots from the extracted data
            (used for manual inspection checks against source plots)
    """
    date_lookup_df = pd.read_csv(dates_file)

    location = input_folder.split("/")[-1]
    print(f"Loading data from location: {location}")

    os.makedirs(output_folder, exist_ok=True)

    for filename in os.listdir(input_folder):

        if filename.startswith("."):
            continue

        print(f"Getting paths from: {filename}")
        paths, _ = svgpathtools.svg2paths(os.path.join(input_folder, filename))

        # Gets paths from file
        xlim, y_lines, trend = categorise_paths(paths)

        trend_converted = convert_units(
            trend, y_lines, xlim, yspan=Y_AXIS_SPAN, xspan=X_AXIS_SPAN
        )

        filename = (
            f"{output_folder}/{input_folder.split('/')[-1]}-{filename.split('.')[0]}"
        )

        if trend_converted:
            xs, ys = tuple(zip(*trend_converted))
        else:
            xs = ys = []

        df = pd.DataFrame(data={"value": ys, "rel_day": xs})

        result_df = pd.merge(
            date_lookup_df, df, left_on="index", right_on="rel_day", how="left"
        )

        result_df = result_df[["value", "date"]]
        result_df["origin"] = location
        try:
            result_df["graph_num"] = filename.split(".")[0].split("-")[1]
        except IndexError:
            result_df["graph_num"] = filename.split(".")[0]

        result_df.to_csv(f"{filename}.csv", sep=",", index=False, float_format="%.3f")

        if plots:
            plt.plot(result_df.date, result_df.value)
            plt.ylim(-80, 80)
            plt.savefig(f"{filename}.png")

            plt.clf()
Turn SVG graphs into CSVs.

    Given an input folder of single plot SVGs convert them into CSV files.

    Args:
        input_folder: Location of SVG files
        output_folder: Location to store the CSVs
        dates_file: Lookup from x axis steps to date
        plots: Boolean flag
            Set to true to create png plots from the extracted data
            (used for manual inspection checks against source plots)
    
Turn SVG graphs into CSVs.
Given an input folder of single plot SVGs convert them into CSV files.
Turn SVG graphs into CSVs . Given an input folder of single plot SVGs convert them into CSV files .
def main(input_folder, output_folder, dates_file, plots):
    date_lookup_df = pd.read_csv(dates_file)
    location = input_folder.split("/")[-1]
    print(f"Loading data from location: {location}")
    os.makedirs(output_folder, exist_ok=True)
    for filename in os.listdir(input_folder):
        if filename.startswith("."):
            continue
        print(f"Getting paths from: {filename}")
        paths, _ = svgpathtools.svg2paths(os.path.join(input_folder, filename))
        xlim, y_lines, trend = categorise_paths(paths)
        trend_converted = convert_units(
            trend, y_lines, xlim, yspan=Y_AXIS_SPAN, xspan=X_AXIS_SPAN
        )
        filename = (
            f"{output_folder}/{input_folder.split('/')[-1]}-{filename.split('.')[0]}"
        )
        if trend_converted:
            xs, ys = tuple(zip(*trend_converted))
        else:
            xs = ys = []
        df = pd.DataFrame(data={"value": ys, "rel_day": xs})
        result_df = pd.merge(
            date_lookup_df, df, left_on="index", right_on="rel_day", how="left"
        )
        result_df = result_df[["value", "date"]]
        result_df["origin"] = location
        try:
            result_df["graph_num"] = filename.split(".")[0].split("-")[1]
        except IndexError:
            result_df["graph_num"] = filename.split(".")[0]
        result_df.to_csv(f"{filename}.csv", sep=",", index=False, float_format="%.3f")
        if plots:
            plt.plot(result_df.date, result_df.value)
            plt.ylim(-80, 80)
            plt.savefig(f"{filename}.png")
            plt.clf()
def main ( input_folder , output_folder , dates_file , plots ) : date_lookup_df = pd . read_csv ( dates_file ) location = input_folder . split ( "/" ) [ - 1 ] print ( f"Loading data from location: {location}" ) os . makedirs ( output_folder , exist_ok = True ) for filename in os . listdir ( input_folder ) : if filename . startswith ( "." ) : continue print ( f"Getting paths from: {filename}" ) paths , _ = svgpathtools . svg2paths ( os . path . join ( input_folder , filename ) ) xlim , y_lines , trend = categorise_paths ( paths ) trend_converted = convert_units ( trend , y_lines , xlim , yspan = Y_AXIS_SPAN , xspan = X_AXIS_SPAN ) filename = ( f"{output_folder}/{input_folder.split('/')[-1]}-{filename.split('.')[0]}" ) if trend_converted : xs , ys = tuple ( zip ( * trend_converted ) ) else : xs = ys = [ ] df = pd . DataFrame ( data = { "value" : ys , "rel_day" : xs } ) result_df = pd . merge ( date_lookup_df , df , left_on = "index" , right_on = "rel_day" , how = "left" ) result_df = result_df [ [ "value" , "date" ] ] result_df [ "origin" ] = location try : result_df [ "graph_num" ] = filename . split ( "." ) [ 0 ] . split ( "-" ) [ 1 ] except IndexError : result_df [ "graph_num" ] = filename . split ( "." ) [ 0 ] result_df . to_csv ( f"{filename}.csv" , sep = "," , index = False , float_format = "%.3f" ) if plots : plt . plot ( result_df . date , result_df . value ) plt . ylim ( - 80 , 80 ) plt . savefig ( f"{filename}.png" ) plt . clf ( )
Turn SVG graphs into CSVs.
Turn SVG graphs into CSVs .
"""Turn SVG graphs into CSVs.

    Given an input folder of single plot SVGs convert them into CSV files.

    Args:
        input_folder: Location of SVG files
        output_folder: Location to store the CSVs
        dates_file: Lookup from x axis steps to date
        plots: Boolean flag
            Set to true to create png plots from the extracted data
            (used for manual inspection checks against source plots)
    """ # Gets paths from file
input_folder
Location of SVG files
Location of SVG files
output_folder
Location to store the CSVs
Location to store the CSVs
dates_file
Lookup from x axis steps to date
Lookup from x axis steps to date
plots
Boolean flag
Set to true to create png plots from the extracted data
(used for manual inspection checks against source plots)
Boolean flag Set to true to create png plots from the extracted data ( used for manual inspection checks against source plots )