Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pydtnsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
discus
pydtnsim
Commits
a55182d1
Commit
a55182d1
authored
7 years ago
by
Jarrod Pas
Browse files
Options
Downloads
Patches
Plain Diff
Adds script to convert shed data into csv.
parent
0ce2dcf5
No related branches found
Branches containing commit
No related tags found
1 merge request
!13
Feature/shed data reformatting
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
util/shed_process
+100
-0
100 additions, 0 deletions
util/shed_process
with
100 additions
and
0 deletions
util/shed_process
0 → 100755
+
100
−
0
View file @
a55182d1
#!/usr/bin/env python
import
csv
import
json
import
sys
from
argparse
import
ArgumentParser
from
collections
import
defaultdict
,
namedtuple
from
itertools
import
groupby
from
os
import
path
import
networkx
as
nx
def
main
(
args
):
seers
=
set
()
observations
=
set
()
with
open
(
args
[
'
csv_path
'
])
as
csv_file
:
csv_file
=
csv
.
DictReader
(
csv_file
)
for
row
in
csv_file
:
time
=
int
(
row
[
args
[
'
time_column
'
]])
seer
=
row
[
args
[
'
seer_column
'
]]
seen
=
row
[
args
[
'
seen_column
'
]]
if
time
>=
0
:
seers
.
add
(
seer
)
observations
.
add
((
time
,
seer
,
seen
))
graph
=
nx
.
Graph
()
for
time
,
seer
,
seen
in
observations
:
if
seen
not
in
seers
:
continue
if
not
graph
.
has_edge
(
seer
,
seen
):
graph
.
add_edge
(
seer
,
seen
,
{
'
times
'
:
set
()})
graph
[
seer
][
seen
][
'
times
'
].
add
(
time
)
nodes
=
max
(
nx
.
connected_components
(
graph
),
key
=
len
)
nodes
=
{
node
:
index
for
index
,
node
in
enumerate
(
nodes
)}
contacts
=
[]
for
node_a
,
node_b
,
times
in
graph
.
edges
(
nbunch
=
nodes
,
data
=
'
times
'
):
times
=
sorted
(
times
)
node_a
,
node_b
=
nodes
[
node_a
],
nodes
[
node_b
]
for
_
,
group
in
groupby
(
enumerate
(
times
),
lambda
p
:
p
[
0
]
-
p
[
1
]):
contact
=
list
(
map
(
lambda
g
:
g
[
1
],
group
))
contacts
.
append
((
contact
[
0
],
node_a
,
node_b
,
True
))
contacts
.
append
((
contact
[
-
1
]
+
1
,
node_a
,
node_b
,
False
))
contacts
.
sort
(
key
=
lambda
c
:
c
[
0
])
start
=
contacts
[
0
][
0
]
duration
=
contacts
[
-
1
][
0
]
-
start
metadata
=
{
'
nodes
'
:
len
(
nodes
),
'
contacts
'
:
len
(
contacts
)
/
2
,
# account for both up and down
'
duration
'
:
duration
,
}
meta_path
=
path
.
join
(
args
[
'
outdir
'
],
'
metadata.json
'
)
with
open
(
meta_path
,
'
w
'
)
as
meta_file
:
json
.
dump
(
metadata
,
meta_file
)
print
(
'
wrote: %s
'
%
meta_path
)
contact_path
=
path
.
join
(
args
[
'
outdir
'
],
'
contact.csv
'
)
with
open
(
contact_path
,
'
w
'
)
as
contact_file
:
writer
=
csv
.
writer
(
contact_file
)
writer
.
writerow
([
'
time
'
,
'
a
'
,
'
b
'
,
'
join
'
])
for
contact
in
contacts
:
contact
=
list
(
map
(
int
,
contact
))
contact
[
0
]
=
(
contact
[
0
]
-
start
)
*
args
[
'
duty_cycle_length
'
]
print
(
contact
)
writer
.
writerow
(
contact
)
print
(
'
wrote: %s
'
%
contact_path
)
def
parse_args
(
args
):
parser
=
ArgumentParser
()
parser
.
add_argument
(
'
csv_path
'
,
help
=
'
path to csv to process
'
)
parser
.
add_argument
(
'
outdir
'
,
help
=
'
directory to output metadata and contacts
'
)
parser
.
add_argument
(
'
time_column
'
,
help
=
'
column used for time slots
'
)
parser
.
add_argument
(
'
seer_column
'
,
help
=
'
column used for devices that scan for others.
'
)
parser
.
add_argument
(
'
seen_column
'
,
help
=
'
column used for devices are seen during a scan.
'
)
parser
.
add_argument
(
'
--duty_cycle_length
'
,
default
=
300
,
type
=
int
)
return
vars
(
parser
.
parse_args
(
args
))
if
__name__
==
'
__main__
'
:
exit
(
main
(
parse_args
(
sys
.
argv
[
1
:])))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment