1+ """Translate TS naming to make it compatible with the new UI naming convention
2+
3+ This script renames the timeslices in the csv files (and actually any other items)
4+ as defined in the tsnaming.csv file (see example in this folder). This is needed
5+ to import models into the new UI as the timeslices need to be named S11, S12, S21,
6+ etc. to indicate day 1 of season 1 (S11), day 3 or season 6 (S63), etc.
7+
8+ Call this script with the following options:
9+ 1. Input data directory - set of csvs to adjust.
10+ 2. Output directory - where to put the converted csvs.
11+
12+ Script created 2023 by Taco Niet. Apache-2.0 license.
13+
14+ """
15+
16+ import os , sys , csv
17+
18+ def main (data_indirectory , data_outdirectory ):
19+ with open ("tsnaming.csv" , "r" ) as tsitems :
20+ tslist = list (csv .reader (tsitems ))
21+ for csv_name in os .listdir (data_indirectory ):
22+ if csv_name .endswith ('.csv' ):
23+ text = open (os .path .join (data_indirectory , csv_name ), "r" )
24+ for line in tslist :
25+ #print(csv_name)
26+ text = '' .join ([i for i in text ]).replace (line [0 ], line [1 ])
27+ x = open (os .path .join (data_outdirectory , csv_name ),"w" )
28+ x .writelines (text )
29+ x .close ()
30+ # end main
31+
32+
33+ if __name__ == '__main__' :
34+ if len (sys .argv ) != 3 :
35+ msg = "Usage: python {} <indir> <outdir>"
36+ print (msg .format (sys .argv [0 ]))
37+ sys .exit (1 )
38+ else :
39+ data_indir = sys .argv [1 ]
40+ data_outdir = sys .argv [2 ]
41+ main (data_indir , data_outdir )
0 commit comments