Skip to content

Commit

Permalink
Fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Keoma Brun committed Nov 8, 2018
1 parent 0b93c67 commit 2c90e17
Show file tree
Hide file tree
Showing 4 changed files with 21,391 additions and 21,405 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ This will create a fille called `fill_myfile.k7` that contains the missing lines

```
{"location": "grenoble", "tx_length": 100, "start_date": "2018-01-11 16:32:22", "stop_date": "2018-01-13 16:21:30", "node_count": 44, "channels": [11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26], "transaction_count": 10, "tx_ifdur": 100}
datetime,src,dst,channels,mean_rssi,pdr,tx_count,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
datetime,src,dst,channel,mean_rssi,pdr,tx_count,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
...
```

Expand All @@ -49,26 +49,26 @@ Ex:
```

## Data
| datetime | src | dst | channels | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|----------|-----------|-------------|----------|----------------|
| iso8601 string | int | int | list | float | float (0-1) | int | int |
| datetime | src | dst | channel | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|---------|-----------|-------------|----------|----------------|
| iso8601 string | int | int | int | float | float (0-1) | int | int |

### Standard example:

| datetime | src | dst | channels | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|----------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | 0 | 1 | [11] | -74.5 | 1.0 | 100 | 1 |
| datetime | src | dst | channel | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|---------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | 0 | 1 | 11 | -74.5 | 1.0 | 100 | 1 |

### The source or destination can be empty (i.e when measured on all the neighbors of the src):

| datetime | src | dst | channels | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|----------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | | | [11] | -74.5 | 0.7 | 100 | 1 |
| datetime | src | dst | channel | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|---------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | | | 11 | -74.5 | 0.7 | 100 | 1 |

### Multiple channels:
### Unknown channel:

| datetime | src | dst | channels | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|----------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | 1 | 2 | [11;12] | -79.5 | 1.0 | 100 | 2 |
| datetime | src | dst | channel | mean_rssi | pdr | tx_count | transaction_id |
|---------------------|---------|---------|---------|-----------|------|----------|----------------|
| 2017-12-19 21:35:41 | 1 | 2 | | -79.5 | 1.0 | 100 | 2 |

When the channel list contains more than one element, it means that the PDR and RSSI value are calculated (averaged) over multiple channels.
When the channel value is empty, it means that the channel is unknown for that measurement.
22 changes: 4 additions & 18 deletions k7/k7.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
REQUIRED_DATA_FIELDS = (
'src',
'dst',
'channels',
'channel',
'mean_rssi',
'pdr',
'tx_count',
Expand Down Expand Up @@ -51,7 +51,6 @@ def read(file_path):
parse_dates = ['datetime'],
index_col = [0], # make datetime column as index
skiprows = 1,
converters = {'channels': lambda x: [int(c) for c in x.strip("[]").split(';')]}
)

return header, data
Expand All @@ -64,10 +63,6 @@ def write(output_file_path, header, data):
:param pandas.Dataframe data:
:return: None
"""

# convert channel list to string
data.channels = data.channels.apply(lambda x: channel_list_to_str(x))

# write to file
with open(output_file_path, 'w') as f:
# write header
Expand Down Expand Up @@ -152,7 +147,7 @@ def fill(file_path):
"datetime": first_date,
"src": src,
"dst": dst,
"channels": [c],
"channel": [c],
"mean_rssi": None,
"pdr": 0,
"tx_count": None,
Expand All @@ -176,7 +171,7 @@ def fill(file_path):
df = pd.concat([df, df_missing])
df.sort_index(inplace=True)

write(file_path + ".filled" , header, df)
write(file_path + ".filled", header, df)

def check(file_path):
"""
Expand Down Expand Up @@ -280,22 +275,13 @@ def get_missing_channels(required_channels, data):
:rtype: list
"""
channels = []
for channel in data.channels:
for channel in data.channel:
channel_list = channel
for channel in channel_list:
if channel not in channels:
channels.append(channel)
return list(set(required_channels) - set(channels))

def channel_list_to_str(channel_list):
"""
[11,12,13] --> "[11;12;13]"
:param list channel_list:
:return:
:rtype: str
"""
return '[' + ';'.join([str(c) for c in channel_list]) + ']'

# ========================= main ==============================================

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 2c90e17

Please sign in to comment.