Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import os
def read_file(filename):
# print(filename)
prefix=filename[filename.find("2")+1]
# print(prefix)
data_sets = {}
with open(filename, "r") as f:
line = True
first = True
while line:
line = f.readline()
#print(line)
if "Balance" in line:
if not first:
data_sets[data_tag+"Center "] = center
data_sets[data_tag+"Asym "] = asym
#set prefix
first = False
# print("Line", line)
data_tag = prefix + (" NoBalance " if "Balance = None" in line else " Balance ")
data_tag+= "Global " if "Global" in line else "Smart "
data_tag+= "CAD " if "CAD = True" in line else ""
# print("tag", data_tag)
center = []
asym = []
# print(data_tag)
continue
if "Data" in line or not line or "NoTN" in line:
continue
entr = line.split(",")
center.append("{{ {},{} }}".format(entr[0], entr[1].replace("e","*^")))
asym.append("{{ {},{} }}".format(entr[0], entr[2].replace("e","*^")))
data_sets[data_tag+"Center "] = center
data_sets[data_tag+"Asym "] = asym
return data_sets
def read_all():
ret = {}
for file in os.listdir():
if file.endswith(".csv"):
# print(file)
new = read_file(file)
ret.update(new)
return ret
def print_data_charts():
ret = read_all()
keys = list(ret.keys())
count = 0
data = []
legend = []
keys.sort(key=lambda x: len(x))
keys.sort(key= lambda x: x[0])
for i in range(len(keys)+1):
if i == len(keys) or (i!=0 and keys[i][0] != keys[i-1][0]):
print("\n\ndatasets = {{ {} }};".format(", ".join(data)))
print("legends = {{ {} }};".format(", ".join(legend)))
data = []
legend = []
print('''plots = Append[
MapThread[
ListPlot[#1, Joined -> True, PlotStyle -> #2,
PlotRange -> {0, 1}] &, {datasets,
ColorData[97] /@ Range[Length[datasets]]}], ListPlot[{}]];
Manipulate[
Show[plots[[datasetNo /. {} -> 4]],
PlotRange -> {0, 1}], {{datasetNo, {1}, ""},
Thread[Range[Length[datasets]] ->
MapThread[
Row[{Pane@
Graphics[{#1, Rectangle[{0, 0}, {10, 1}]}, ImageSize -> 20],
" " <> ToString@legends[[#2]]},
BaselinePosition -> Center] &, {ColorData[97] /@
Range[Length[datasets]], Range[Length[datasets]]}]],
ControlType -> CheckboxBar, BaselinePosition -> Center,
Method -> "Active", Appearance -> "Vertical"},
ControlPlacement -> Right]''')
print("\n\n\n")
count+=1
if i == len(keys):
continue
data.append("".join(keys[i].split(" ")))
legend.append(" \"{}\" ".format(keys[i]))
print("{} = {{ {} }};".format("".join(keys[i].split(" ")), ", ".join(ret[keys[i]])) )
# test = read_all()
# for key in test:
# print(key, test[key])
print_data_charts()