forked from pfyhr/evReqGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonwriter.py
More file actions
33 lines (27 loc) · 1.04 KB
/
Copy pathjsonwriter.py
File metadata and controls
33 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import json
import pathlib
def output_json(csvfile, name, power):
#load the csvfile
data = np.genfromtxt(csvfile, skip_header=0, delimiter=',')
#make a dict of it, as naji suggested!
xys = [{'x':i, 'y':j} for i,j in data]
string_dict = {'xydata': xys, 'Power': power, 'Modelname': f'{name}'}
#find the filename and put ut in the desired path
fpath = pathlib.Path(csvfile)
#print(fpath.stem)
#and write it to .json file
with open(f'./static/json/{fpath.stem}.json', 'w') as json_file:
json.dump(string_dict, json_file, indent = 4)
def glob_csvs(foldername):
counter = 0
for csvpath in pathlib.Path(foldername).glob("*.csv"):
#do something to calculate power from the csv.
output_json(csvpath, csvpath.stem, 123)
counter += 1
return f'converted {counter} .csv files to .json'
if __name__ == "__main__":
#path = 'static/csv/egolfSimData.csv'
#output_json(path,'Leaf_real', 80)
message = glob_csvs('./static/csv/')
print(message)