# Path: classification/metadata.py
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# 
# VESSEL_CATEGORIES = sorted(categories(schema))
# 
# TEST_SPLIT = 'Test'
# 
# Path: classification/metadata.py
# PRIMARY_VESSEL_CLASS_COLUMN = 'label'
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# VESSEL_CATEGORIES = sorted(categories(schema))
# TRAINING_SPLIT = 'Training'
# TEST_SPLIT = 'Test'
#     MAX_WEIGHT = 100.0
# def atomic(obj):
# def categories(obj, include_atomic=True):
# def stable_hash(x):
#     def __init__(self,
#                  metadata_dict,
#                  fishing_ranges_map):
#     def vessel_weight(self, id_):
#     def vessel_label(self, label_name, id_):
#     def ids_for_split(self, split):
#     def weighted_training_list(self,
#                                random_state,
#                                split,
#                                max_replication_factor,
#                                row_filter=lambda row: True,
#                                boundary=1):
#     def fishing_range_only_list(self, random_state, split):
# def read_vessel_time_weighted_metadata_lines(available_ids, lines,
#                                              fishing_range_dict, split):
# def read_vessel_time_weighted_metadata(available_ids,
#                                        metadata_file,
#                                        fishing_range_dict={},
#                                        split=0):
# def read_vessel_multiclass_metadata_lines(available_ids, lines,
#                                           fishing_range_dict):
# def metadata_file_reader(metadata_file):
# def read_vessel_multiclass_metadata(available_ids,
#                                     metadata_file,
#                                     fishing_range_dict={}):
# def find_available_ids(feature_path):
# def parse_date(date):
# def read_fishing_ranges(fishing_range_file):
# def build_multihot_lookup_table():
# def multihot_encode(label):
# class VesselMetadata(object):


import os
import csv
import subprocess
import numpy as np
import dateutil.parser
import logging
import argparse
import sys
import yattag
import gzip
import dateutil.parser
import datetime
import pytz
import pandas as pd
from collections import namedtuple, defaultdict
from classification.metadata import VESSEL_CLASS_DETAILED_NAMES, VESSEL_CATEGORIES, TEST_SPLIT
from classification.metadata import raw_schema, schema, atomic

This compute metrics for the table `vessel_char_vid_features_v20190509`, comparing
results with the known values in the table `char_info_v20190509`. This second table
is typically derived from the vessel database using train/create_train_info.py.
The results, and html file, are written to dest path.

    python -m classification.metrics.compute_vessel_metrics \
        --inference-table machine_learning_dev_ttl_120d.vessel_char_vid_features_v20190509  \
        --label-table machine_learning_dev_ttl_120d.char_info_v20190509 \
        --dest-path ./test_inference_metrics_0509.html

*Note: despite the table, name this table is in terms of vessel_id*

"""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function

coarse_categories = [
    'bunker_or_tanker', 'cargo_or_reefer', 'passenger', 'tug',  'research', 'other_not_fishing*',
    'drifting_longlines', 'gear', 'purse_seines', 'set_gillnets', 'set_longlines', 'pots_and_traps',
     'trawlers', 'squid_jigger',  'other_fishing*'
    ]


raw_names = [x[:-1] for x in raw_schema.split() if x.strip()]   
names = [x for x in raw_names if x in VESSEL_CLASS_DETAILED_NAMES]
fine_mapping = [(x, set([x])) for x in names]



# Path: classification/metadata.py
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# 
# VESSEL_CATEGORIES = sorted(categories(schema))
# 
# TEST_SPLIT = 'Test'
# 
# Path: classification/metadata.py
# PRIMARY_VESSEL_CLASS_COLUMN = 'label'
# VESSEL_CLASS_DETAILED_NAMES = sorted(atomic(schema))
# VESSEL_CATEGORIES = sorted(categories(schema))
# TRAINING_SPLIT = 'Training'
# TEST_SPLIT = 'Test'
#     MAX_WEIGHT = 100.0
# def atomic(obj):
# def categories(obj, include_atomic=True):
# def stable_hash(x):
#     def __init__(self,
#                  metadata_dict,
#                  fishing_ranges_map):
#     def vessel_weight(self, id_):
#     def vessel_label(self, label_name, id_):
#     def ids_for_split(self, split):
#     def weighted_training_list(self,
#                                random_state,
#                                split,
#                                max_replication_factor,
#                                row_filter=lambda row: True,
#                                boundary=1):
#     def fishing_range_only_list(self, random_state, split):
# def read_vessel_time_weighted_metadata_lines(available_ids, lines,
#                                              fishing_range_dict, split):
# def read_vessel_time_weighted_metadata(available_ids,
#                                        metadata_file,
#                                        fishing_range_dict={},
#                                        split=0):
# def read_vessel_multiclass_metadata_lines(available_ids, lines,
#                                           fishing_range_dict):
# def metadata_file_reader(metadata_file):
# def read_vessel_multiclass_metadata(available_ids,
#                                     metadata_file,
#                                     fishing_range_dict={}):
# def find_available_ids(feature_path):
# def parse_date(date):
# def read_fishing_ranges(fishing_range_file):
# def build_multihot_lookup_table():
# def multihot_encode(label):
# class VesselMetadata(object):


# Path: classification/metrics/compute_vessel_metrics.py
import os
import csv
import subprocess
import numpy as np
import dateutil.parser
import logging
import argparse
import sys
import yattag
import gzip
import dateutil.parser
import datetime
import pytz
import pandas as pd
from collections import namedtuple, defaultdict
from classification.metadata import VESSEL_CLASS_DETAILED_NAMES, VESSEL_CATEGORIES, TEST_SPLIT
from classification.metadata import raw_schema, schema, atomic


This compute metrics for the table `vessel_char_vid_features_v20190509`, comparing
results with the known values in the table `char_info_v20190509`. This second table
is typically derived from the vessel database using train/create_train_info.py.
The results, and html file, are written to dest path.

    python -m classification.metrics.compute_vessel_metrics \
        --inference-table machine_learning_dev_ttl_120d.vessel_char_vid_features_v20190509  \
        --label-table machine_learning_dev_ttl_120d.char_info_v20190509 \
        --dest-path ./test_inference_metrics_0509.html

*Note: despite the table, name this table is in terms of vessel_id*

"""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function

coarse_categories = [
    'bunker_or_tanker', 'cargo_or_reefer', 'passenger', 'tug',  'research', 'other_not_fishing*',
    'drifting_longlines', 'gear', 'purse_seines', 'set_gillnets', 'set_longlines', 'pots_and_traps',
     'trawlers', 'squid_jigger',  'other_fishing*'
    ]


raw_names = [x[:-1] for x in raw_schema.split() if x.strip()]   
names = [x for x in raw_names if x in VESSEL_CLASS_DETAILED_NAMES]
fine_mapping = [(x, set([x])) for x in names]



all_classes = set(VESSEL_CLASS_DETAILED_NAMES) 