Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Python by PaulMcG ( 3 years ago )
import pyparsing as pp
integer = pp.pyparsing_common.integer
number = pp.pyparsing_common.number
date = pp.Group(integer * 3)
time = integer
record = (integer("id")
+ date("date")
+ time("time")
+ integer("set_count")
+ number[...]("raw"))
def regroup_raw(t):
# get the raw values, and regroup into data sets
raw_vals = t.pop("raw")
data_set_size = len(raw_vals) // t.set_count
# make data sets as list of lists, and save as "data"
t["data"] = [raw_vals[n*data_set_size:(n+1)*data_set_size]
for n in range(t.set_count)]
# add parse-time callback to do data regrouping
record.addParseAction(regroup_raw)
# try it out!
# (I had to modify the 105 count to just 15, since this seemed to be truncated in the pasted example text)
line = "12868 88 11 26 1130 15 13 11.0 75 25.7 1016.00 1173.00 21.0 1000 16.0 77 23.1 981.60 1144.00 19.2 2000 17.0 77 20.1 947.90 1117.00 18.0 3000 17.0 76 17.7 915.10 1087.00 16.6 4000 19.0 75 15.6 883.10 1058.00 14.6 5000 22.0 74 12.4 852.00 1033.00 11.1 6000 24.0 72 10.5 821.60 1005.00 6.7 7000 25.0 70 9.8 792.20 971.40 5.1 8000 18.0 75 9.1 763.70 941.40 -10.5 9000 16.0 81 11.5 736.30 900.10 -14.5 10000 15.0 83 10.2 709.90 871.90 -14.8 11000 15.0 79 8.2 684.30 846.50 -16.3 12000 16.0 75 5.9 659.50 822.60 -18.0 13000 17.0 78 3.6 635.30 799.30 -19.7 14000 18.0 82 2.0 611.90 774.30 -20.9 15000"
parsed = record.parseString(line)
print(parsed.dump())
for dataset in parsed.data:
print(dataset)
# prints:
[12868, [88, 11, 26], 1130, 15, 13, 11.0, ...
- date: [88, 11, 26]
- id: 12868
- set_count: 15
- time: 1130
[13, 11.0, 75, 25.7, 1016.0, 1173.0, 21.0]
[1000, 16.0, 77, 23.1, 981.6, 1144.0, 19.2]
[2000, 17.0, 77, 20.1, 947.9, 1117.0, 18.0]
[3000, 17.0, 76, 17.7, 915.1, 1087.0, 16.6]
[4000, 19.0, 75, 15.6, 883.1, 1058.0, 14.6]
[5000, 22.0, 74, 12.4, 852.0, 1033.0, 11.1]
[6000, 24.0, 72, 10.5, 821.6, 1005.0, 6.7]
[7000, 25.0, 70, 9.8, 792.2, 971.4, 5.1]
[8000, 18.0, 75, 9.1, 763.7, 941.4, -10.5]
[9000, 16.0, 81, 11.5, 736.3, 900.1, -14.5]
[10000, 15.0, 83, 10.2, 709.9, 871.9, -14.8]
[11000, 15.0, 79, 8.2, 684.3, 846.5, -16.3]
[12000, 16.0, 75, 5.9, 659.5, 822.6, -18.0]
[13000, 17.0, 78, 3.6, 635.3, 799.3, -19.7]
[14000, 18.0, 82, 2.0, 611.9, 774.3, -20.9]
Revise this Paste