-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keoma Brun
committed
Mar 29, 2018
1 parent
814cd50
commit 96ce5a4
Showing
13 changed files
with
43,052 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,6 @@ ENV/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# pycharm | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
install: | ||
- pip install -r requirements.txt | ||
script: | ||
- pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,61 @@ | ||
# k7 | ||
k7 dataset | ||
|
||
[![Version](https://img.shields.io/pypi/v/k7.svg)](https://pypi.python.org/pypi/k7) | ||
[![Licence](https://img.shields.io/pypi/l/k7.svg)](https://pypi.python.org/pypi/k7) | ||
[![Build](https://travis-ci.org/keomabrun/k7.svg?branch=master)](https://travis-ci.org/keomabrun/k7) | ||
|
||
![Cassette](https://raw.githubusercontent.com/keomabrun/k7/master/docs/static/cassette.png) | ||
|
||
CCBY: Cassette by Alvaro Cabrera from the Noun Project | ||
|
||
# Usage | ||
|
||
|
||
### Check file format | ||
|
||
``` | ||
python -m k7.k7 --check myfile.k7 | ||
``` | ||
|
||
# k7 format | ||
|
||
``` | ||
{"site": "grenoble", "tx_length": 100, "start_date": "2018-01-11 16:32:22", "stop_date": "2018-01-13 16:21:30", "tx_count": 100, "node_count": 44, "channel_count": 16, "transaction_count": 10, "tx_ifdur": 100} | ||
datetime,src,dst,channel,mean_rssi,pdr,transaction_id | ||
2018-01-11 16:33:07,05-43-32-ff-03-d9-a5-68,05-43-32-ff-02-d5-25-53,11,-53.2,1.0,0 | ||
2018-01-11 16:33:07,05-43-32-ff-03-d9-a5-68,05-43-32-ff-03-db-b2-76,11,-84.03,0.97,0 | ||
2018-01-11 16:33:07,05-43-32-ff-03-d9-a5-68,05-43-32-ff-03-d7-93-78,11,-83.88,1.0,0 | ||
2018-01-11 16:33:30,05-43-32-ff-03-d6-95-84,05-43-32-ff-03-da-a9-72,11,-67.03,1.0,0 | ||
2018-01-11 16:33:30,05-43-32-ff-03-d6-95-84,05-43-32-ff-03-da-c0-81,11,-70.0,1.0,0 | ||
... | ||
``` | ||
|
||
## Header | ||
|
||
Each k7 starts with a one-line header. The header is the json dump of a dict. The header contains the dataset meta data. | ||
Ex: | ||
``` | ||
{"site": "grenoble", "tx_length": 100, "start_date": "2017-06-20 16:22:15", "stop_date": "2017-06-21 10:29:29", "tx_count": 100, "node_count": 50, "channel_count": 16, "transaction_count": 10, "tx_ifdur": 10} | ||
``` | ||
|
||
## Data | ||
| datetime | src | dst | channel | mean_rssi | pdr | transaction_id | | ||
|---------------------|-------------|-------------|---------|-----------|-------------|----------------| | ||
| iso8601 string | string | string | string | float | float (0-1) | int | | ||
|
||
### Standard example: | ||
|
||
| datetime | src | dst | channel | mean_rssi | pdr | transaction_id | | ||
|---------------------|-------------|-------------|---------|-----------|------|----------------| | ||
| 2017-12-19 21:35:41 | d7-94-75 | d7-94-79 | 11 | -74.5 | 1.0 | 1 | | ||
|
||
### The source or destination can be empty (i.e when measured on all the neighbors of the src): | ||
|
||
| datetime | src | dst | channel | mean_rssi | pdr | transaction_id | | ||
|---------------------|-------------|-------------|---------|-----------|------|----------------| | ||
| 2017-12-19 21:35:41 | d7-94-75 | d7-94-79 | 11 | -74.5 | 0.7 | 1 | | ||
|
||
### The channel can be a range: | ||
| datetime | src | dst | channel | mean_rssi | pdr | transaction_id | | ||
|---------------------|-------------|-------------|---------|-----------|------|----------------| | ||
| 2017-12-19 21:35:41 | d7-94-75 | d7-94-79 | 11-25 | -79.5 | 1.0 | 2 | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
""" | ||
This module provides methods to parse and manipulate K7 files | ||
""" | ||
|
||
import json | ||
import pandas as pd | ||
|
||
REQUIRED_HEADER_FIELDS = [ | ||
'start_date', | ||
'stop_date', | ||
'site', | ||
] | ||
REQUIRED_DATA_FIELDS = [ | ||
'datetime', | ||
'src', | ||
'dst', | ||
'channel', | ||
'mean_rssi', | ||
'pdr', | ||
'transaction_id' | ||
] | ||
|
||
__version__ = "0.0.3" | ||
|
||
def read(file_path): | ||
""" | ||
Read the k7 | ||
:param file_path: | ||
:return: | ||
:rtype: dict, pandas.Dataframe | ||
""" | ||
# read header | ||
with open(file_path, 'r') as f: | ||
header = json.loads(f.readline()) | ||
|
||
# read data | ||
df = pd.read_csv(file_path, | ||
parse_dates = ['datetime'], | ||
index_col = [0], # make datetime column as index | ||
dtype={'channel': str}, | ||
skiprows=1, | ||
) | ||
return header, df | ||
|
||
def write(output_file_path, header, data): | ||
""" | ||
Write the k7 | ||
:param output_file_path: | ||
:param dict header: | ||
:param pandas.Dataframe data: | ||
:return: | ||
""" | ||
with open(output_file_path, 'w') as f: | ||
# write header | ||
json.dump(header, f) | ||
f.write('\n') | ||
|
||
# write data | ||
data.to_csv(f) | ||
|
||
def match(trace, source, destination, channel=None, transaction_id=None): | ||
""" | ||
Find matching rows in the k7 | ||
:param pandas.Dataframe trace: | ||
:param str source: | ||
:param str destination: | ||
:param int channel: | ||
:param int transaction_id: | ||
:return: None | pandas.core.series.Series | ||
""" | ||
|
||
# channel | ||
if channel is None: | ||
channel = "11-26" | ||
else: | ||
channel = str(channel + 11) | ||
|
||
# transaction id | ||
if transaction_id is None: | ||
transaction_id = trace.transaction_id.min() | ||
|
||
# get rows | ||
series = trace[(trace.src == source) & | ||
(trace.dst == destination) & | ||
(trace.channel == channel) & | ||
(trace.transaction_id == transaction_id) | ||
] | ||
|
||
if len(series) >= 1: | ||
return series.iloc[0] # return first element | ||
else: | ||
return None | ||
# elif len(series) > 1: | ||
# log.warn("Multiple occurrences found for same transaction ID.") | ||
|
||
def check(file_path): | ||
""" | ||
Check if k7 format is respected | ||
:return: | ||
""" | ||
|
||
header, df = read(file_path) | ||
|
||
for required_header in REQUIRED_HEADER_FIELDS: | ||
if required_header not in header: | ||
print "Header {0} missing".format(required_header) | ||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
# parse arguments | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--check", | ||
help="check the dataset format", | ||
type=str, | ||
dest='file_to_check', | ||
) | ||
parser.add_argument('-v', '--version', | ||
action='version', | ||
version='%(prog)s ' + __version__) | ||
args = parser.parse_args() | ||
|
||
# run corresponding method | ||
if hasattr(args, "file_to_check"): | ||
check(args.file_to_check) | ||
else: | ||
print "Command {0} does not exits." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
matplotlib |
Oops, something went wrong.