-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart.py
executable file
·107 lines (86 loc) · 2.46 KB
/
chart.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/env python3
# -*- coding: utf-8 -*-
import sys
import offset
import matrix
import common
def generateJS( js, fname ):
"""
generateJS produce JavaScript file which use to generate
Chart.
js The offset coordination that have transpose to
js formation.
"""
end = '\n\t\t});\t\n});'
ftemplate = open('/export/home/liuhui/bin/data_template.js', 'r').readlines()
Js = js + end
f = open( fname, 'w' )
f.writelines(ftemplate)
f.write( Js )
f.close()
print("generate JavaScript sucessfully!")
def ChartData( data ):
name = "Orbital"
section = 'series: ['
i = 0
for d in data:
section = section + "{\nvisible: false,\nname: '" + name + str(i) + \
"',\ndata: [" + data[i] + "]\n}, "
i += 1
section = section[:-2] + ']'
return section
def ReadData( fName = '/tmp/chartdata' ):
"""
ReadData read offset data from file
"""
blocks = common.ReadDataFromFile( fName )
return blocks
def FormatOutput( data ):
"""
FormatOutput make the output information is perfect.
data a list
"""
nColumn = len(data[0])
nRow = len(data)
i = 0
oData = []
while i < nRow:
tmp = ', '.join( str(x) for x in data[i] )
oData.append(tmp)
i += 1
return oData
def HandleData(bData):
"""
HandleData transpose the input data to a matrix
bData a List
"""
nColumn = len(bData)
i = 0
data = []
while i < nColumn:
one = bData[i].split(' ')
one[-1] = one[-1][:-1]
#Shit! forgot add a comma, Waste plenty of time to debug.
data.append( one[1:] )
i += 1
#check the data,
if len(data[0]) != len(data[1]):
print("The Data May be not completely! Please Check it.")
return data
if __name__ == "__main__":
n = len(sys.argv)
if n == 1:
print("Input error!")
print( "chart [-w | datafile] distfile " )
sys.exit(1)
distfile = 'OffsetChart'
blocks = ReadData(sys.argv[1])
wData = HandleData(blocks)
transData = matrix.transpose(wData)
oData = FormatOutput(transData)
chart = ChartData(oData)
generateJS( chart, distfile + '.js' )
#produce a file that contain offset data used to check
f = open( distfile + '.dat', 'w' )
f.writelines(repr(transData))
f.close()