python - Pattern for associating pyparsing results with a linked-list of nodes -


i have defined pyparsing rule parse text syntax-tree...

text commands:

add iteration name = "cisco 10m/half"     append observation name = "packet loss 1"         assign observation results_text = 0.0         assign observation results_bool = true         append datapoint             assign datapoint metric = txpackets             assign datapoint units = packets         append datapoint             assign datapoint metric = txpackets             assign datapoint units = packets     append observation name = "packet loss 2"         append datapoint             assign datapoint metric = txpackets             assign datapoint units = packets         append datapoint             assign datapoint metric = txpackets             assign datapoint units = packets 

syntax tree:

['add', 'iteration', ['name', 'cisco 10m/half']] ['append', 'observation', ['name', 'packet loss 1']] ['assign', 'observation', ['results_text', '0.0']] ['assign', 'observation', ['results_bool', 'true']] ['append', 'datapoint'] ['assign', 'datapoint', ['metric', 'txpackets']] ['assign', 'datapoint', ['units', 'packets']] ... 

i'm trying associate nested key-value pairs in syntax-tree above linked-list of objects... heirarchy looks (each word namedtuple... children in heirarchy on parents' list of children):

log: [      iteration: [          observation:              [datapoint, datapoint],          observation:              [datapoint, datapoint]     ] ] 

the goal of build generic test data-acquisition platform drive flow of tests against network gear, , record results. after data in format, same data structure used build test report. answer question in comments below, chose linked list because seemed easiest way sequentially dequeue information when writing report. however, rather not assign iteration or observation sequence numbers before finishing tests... in case find problems , insert more observations in course of conducting test. theory position of each element in list sufficient, i'm willing change if it's part of problem.

the problem i'm getting lost trying assign key-values objects in linked list after it's built. instance, after insert observation namedtuple first iteration, have trouble reliably handling update of assign observation results_bool = true in example above.

is there generalized design pattern handle situation? have googled while, can't seem make link between parsing text (which can do) , managing data-heirarchy (the main problem). hyperlinks or small demo code fine... need pointers on right track.

i not aware of actual design pattern you're looking for, have great passion issue @ hand. work heavily network devices , parsing , organizing data large ongoing challenge me.

it's clear problem not parsing data, afterwards. need think meaning attaching data have parsed. nested-list method might work if objects containing lists meaningful.

namedtuples great quick-and-dirty class-ish behavior, fall flat when need them outside of basic attribute access, considering tuples immutable. seems me you'll want replace namedtuple objects full-blown classes. way can highly customize behavior , methods available.

for example, know iteration contain 1 or more observation objects contain 1 or more datapoint objects. if can accurately describe relationships, sets on path handling them.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -