Skip to content

Commit

Permalink
Merge pull request #33 from hpuhr/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
hpuhr authored Jun 28, 2021
2 parents 7446909 + 53ce9ea commit b3ae0fe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set ( CMAKE_BUILD_TYPE RelWithDebInfo ) #Debug RelWithDebInfo Release

project( jASTERIX )
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "8")
SET(CPACK_PACKAGE_VERSION_MINOR "1")
SET(CPACK_PACKAGE_VERSION_PATCH "0")

message(" System: ${CMAKE_SYSTEM}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down
58 changes: 39 additions & 19 deletions analyze/data_items.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import sys
import json
Expand Down Expand Up @@ -76,32 +76,52 @@ def print(self, count_parent=None):
val_stat.print(self.count)

class DataItemStatisticsCalculator:
def __init__(self):
def __init__(self, per_source):
self._per_source = per_source
self.__num_records = 0
self.__statistics = {} # type: Dict[str, DataItemStatistic]
self.__statistics = {} # type: Dict[(int, int), Dict[str, DataItemStatistic]]

@property
def num_records(self):
return self.__num_records

def process_record(self, cat, record):

sac = None
sic = None

if self._per_source:
sac = find_value('010.SAC', record)
sic = find_value('010.SIC', record)

assert sac is not None and sic is not None

self.__num_records += 1

cat_str = str(cat).zfill(3)

if cat_str not in self.__statistics:
self.__statistics[cat_str] = DataItemStatistic(cat_str)
if (sac, sic) not in self.__statistics:
self.__statistics[(sac, sic)] = {}

if cat_str not in self.__statistics[(sac, sic)]:
self.__statistics[(sac, sic)][cat_str] = DataItemStatistic(cat_str)

self.__statistics[cat_str].process_object(record)
self.__statistics[(sac, sic)][cat_str].process_object(record)

def print(self):
print('num records {}'.format(self.__num_records))

print('data items')
for cat, stat in sorted(self.__statistics.items()):
print()
stat.print()
for (sac, sic), stat_dict in sorted(self.__statistics.items()):

if self._per_source:
print('data items for {}/{}'.format(sac, sic))
else:
print('data items')

for cat, stat in sorted(stat_dict.items()):
print()
stat.print()
print('\n\n')


# filter functions return True if record should be skipped
Expand All @@ -122,32 +142,32 @@ def filter_cats(cat, record):
def main(argv):

parser = argparse.ArgumentParser(description='ASTERIX data item analysis')
parser.add_argument('--framing', help='Framing True or False', required=True)
parser.add_argument('--framing', help='Framing', default=False, action='store_true', required=False)
parser.add_argument('--cats', help='ASTERIX categories to be analyzed as CSV', required=False)
parser.add_argument('--per_source', help='Whether to do analysis per SAC/SIC', default=False, action='store_true', required=False)

args = parser.parse_args()

assert args.framing is not None
assert args.framing == 'True' or args.framing == 'False'
framing = args.framing == 'True'
#assert args.framing is not None
#assert args.framing == 'True' or args.framing == 'False'
print('framing {} '.format(args.framing))

global cat_list
if args.cats is not None:
cat_list = args.cats.split(",")
cat_list = [int(i) for i in cat_list]

print('framing {}'.format(framing))
print('cats {}'.format(cat_list))
print('per-source {} '.format(args.per_source))

num_blocks = 0

statistics_calc = DataItemStatisticsCalculator() # type: DataItemStatisticsCalculator
statistics_calc = DataItemStatisticsCalculator(args.per_source) # type: DataItemStatisticsCalculator

if cat_list is None: # without filtering
record_extractor = RecordExtractor (framing, statistics_calc.process_record) # type: RecordExtractor
record_extractor = RecordExtractor (args.framing, statistics_calc.process_record) # type: RecordExtractor
else: # with filtering lambda
record_extractor = RecordExtractor(framing, statistics_calc.process_record, filter_cats) # type: RecordExtractor

record_extractor = RecordExtractor(args.framing, statistics_calc.process_record, filter_cats) # type: RecordExtractor

start_time = time.time()

Expand Down
2 changes: 1 addition & 1 deletion definitions/categories/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"010":{
"comment":"Category 010 Transmission of Monosensor Surface Movement Data",
"default_edition":"0.24_sensis",
"default_edition":"0.31",
"default_mapping":"",
"editions":{
"0.24_sensis":{
Expand Down
2 changes: 1 addition & 1 deletion src/asterix/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ size_t Record::parseItem(const char* data, size_t index, size_t size, size_t cur

if (special_purpose_field_present)
{
size_t re_bytes = static_cast<size_t>(data[index + parsed_bytes]);
size_t re_bytes = static_cast<unsigned char>(data[index + parsed_bytes]);

parsed_bytes += 1; // read 1 len byte
re_bytes -= 1; // includes 1 len byte
Expand Down

0 comments on commit b3ae0fe

Please sign in to comment.