exit(0) # now read in 1A.csv to get voltage_actual against wh # in = time, voltage_drain, current last_time = 0 total_wh = 0 fin = open("1A.csv") fout = open("1A_treated.csv", 'w') fout.write("total_wh, voltage_actual\n") while (True): l = fin.readline() if len(l) == 0: break spl = l.split(',') try: time = float(spl[0]) voltage_drain = float(spl[1]) current = float(spl[2]) total_wh += (time - last_time) * voltage_drain * current / 3600 last_time = time fout.write("%f,%f\n" % (total_wh, f.interpolate(voltage_drain))) except Exception, e: print "An exception occurred: " + str(e) print "It's probably ok" fin.close() fout.close()
print "It's probably ok" f = Function(data=data) for i in xrange(len(data)): v = data[i][0] wh = data[i][1] data[i] = (v, (wh - min_wh) / (max_wh - min_wh)) SPACING = (max_v - min_v) / 100 fout.write('[\n') v = min_v while v <= max_v: interpolated_wh = f.interpolate(v) fout.write("{%d,%d},\n" % (int(v * 1000000), int(interpolated_wh * 1000000))) v += SPACING fout.write(']\n') fout.write('[\n') SPACING = (max_v - min_v) / 10000 last_v = min_v last_wh = f.interpolate(min_v) max_delta_v = 0 max_delta_wh = 0 min_delta_v = float("inf") min_delta_wh = float("inf")
print "It's probably ok" f = Function(data=data) for i in xrange(len(data)): v = data[i][0] wh = data[i][1] data[i] = (v, (wh - min_wh) / (max_wh - min_wh)) SPACING = (max_v - min_v) / 100 fout.write('[\n') v = min_v while v <= max_v: interpolated_wh = f.interpolate(v) fout.write("{%d,%d},\n" % (int(v*1000000), int(interpolated_wh*1000000))) v += SPACING fout.write(']\n') fout.write('[\n') SPACING = (max_v - min_v) / 10000 last_v = min_v last_wh = f.interpolate(min_v) max_delta_v = 0 max_delta_wh = 0 min_delta_v = float("inf") min_delta_wh = float("inf") v = min_v