def expire_activity_later(aid): """ Later version of the above, to be called at the activity when datetime """ logger.warning('expire_activity_later aid:%s' % str(aid)) activity = Activity.objects.get(id=aid) if activity.status == Activity.EXPIRED: return 'Activity %s already expired' % str(aid) activity.expire() activity.save() # notification_tasks.no_confirms(aid) Metric.add_activity_metric(activity) return 'Activity later %s expired successfully' % str(aid)
def create(self, metric_request): metric = Metric( sensor_type = metric_request['sensor_type'], sensor_id = metric_request['sensor_id'], timestamp_s = metric_request['timestamp_s'], metric_name = metric_request['metric_name'], metric_value = metric_request['metric_value'], tags = metric_request['tags'] ) influx_body = [{ "measurement": metric.metric_name, "tags": { "sensor_type": metric.sensor_type, "sensor_id": metric.sensor_id }, "time": int(metric.timestamp_s), "fields": { "value": float(metric.metric_value) } }] add_tags = metric.tags for tag in add_tags: for k in tag.keys(): for data in influx_body: data["tags"][k] = tag[k] write_data(influx_body) return
def expire_activity_default(aid): """ Called when the activity is due to expire and expires it Also adds the activity keener metrics to the Metric store """ activity = Activity.objects.get(id=aid) if activity.status == Activity.EXPIRED: logger.warning('Activity %s already expired' % str(aid)) return 'Activity %s already expired' % str(aid) if activity.is_confirmed() and not activity.when: return "Default expiry on %s not applied, as will be pulled by a later task" % str(aid) now = datetime.datetime.now() diff = activity.expiry - now if diff.total_seconds() <= 120: #If the activity is meant to be expired in teh next 2 mins we do it activity.expire() activity.save() Metric.add_activity_metric(activity) # notification_tasks.no_confirms(aid) return 'Activity default %s expired successfully' % str(aid) else: #Otherwise we don't and we set a new task to run at the correct time expire_activity_default.apply_async(args=[aid], eta=activity.expiry)
def metrics_record_response_time(endpoint, timestamp, response_time, metrics_groups): global metrics_definitions logger.debug("metrics_record_response_time({}, {}, {})".format( endpoint.url, str(timestamp), str(response_time))) metric = Metric(endpoint=endpoint, timestamp=timestamp, name='RESPONSE-TIME', data=response_time) deliver_metric_to_groups(metric, metrics_groups, metrics_definitions)
def parse_yaml_config(config_file_path, with_notary, with_trivy, with_chartmuseum): ''' :param configs: config_parser object :returns: dict of configs ''' with open(config_file_path) as f: configs = yaml.safe_load(f) config_dict = { 'portal_url': 'http://portal:8080', 'registry_url': 'http://registry:5000', 'registry_controller_url': 'http://registryctl:8080', 'core_url': 'http://core:8080', 'core_local_url': 'http://127.0.0.1:8080', 'token_service_url': 'http://core:8080/service/token', 'jobservice_url': 'http://jobservice:8080', 'trivy_adapter_url': 'http://trivy-adapter:8080', 'notary_url': 'http://notary-server:4443', 'chart_repository_url': 'http://chartmuseum:9999' } config_dict['hostname'] = configs["hostname"] config_dict['protocol'] = 'http' http_config = configs.get('http') or {} config_dict['http_port'] = http_config.get('port', 80) https_config = configs.get('https') if https_config: config_dict['protocol'] = 'https' config_dict['https_port'] = https_config.get('port', 443) config_dict['cert_path'] = https_config["certificate"] config_dict['cert_key_path'] = https_config["private_key"] if configs.get('external_url'): config_dict['public_url'] = configs.get('external_url') else: if config_dict['protocol'] == 'https': if config_dict['https_port'] == 443: config_dict['public_url'] = '{protocol}://{hostname}'.format( **config_dict) else: config_dict[ 'public_url'] = '{protocol}://{hostname}:{https_port}'.format( **config_dict) else: if config_dict['http_port'] == 80: config_dict['public_url'] = '{protocol}://{hostname}'.format( **config_dict) else: config_dict[ 'public_url'] = '{protocol}://{hostname}:{http_port}'.format( **config_dict) # DB configs db_configs = configs.get('database') if db_configs: # harbor db config_dict['harbor_db_host'] = 'postgresql' config_dict['harbor_db_port'] = 5432 config_dict['harbor_db_name'] = 'registry' config_dict['harbor_db_username'] = '******' config_dict['harbor_db_password'] = db_configs.get("password") or '' config_dict['harbor_db_sslmode'] = 'disable' config_dict['harbor_db_max_idle_conns'] = db_configs.get( "max_idle_conns") or default_db_max_idle_conns config_dict['harbor_db_max_open_conns'] = db_configs.get( "max_open_conns") or default_db_max_open_conns if with_notary: # notary signer config_dict['notary_signer_db_host'] = 'postgresql' config_dict['notary_signer_db_port'] = 5432 config_dict['notary_signer_db_name'] = 'notarysigner' config_dict['notary_signer_db_username'] = '******' config_dict['notary_signer_db_password'] = '******' config_dict['notary_signer_db_sslmode'] = 'disable' # notary server config_dict['notary_server_db_host'] = 'postgresql' config_dict['notary_server_db_port'] = 5432 config_dict['notary_server_db_name'] = 'notaryserver' config_dict['notary_server_db_username'] = '******' config_dict['notary_server_db_password'] = '******' config_dict['notary_server_db_sslmode'] = 'disable' # Data path volume config_dict['data_volume'] = configs['data_volume'] # Initial Admin Password config_dict['harbor_admin_password'] = configs["harbor_admin_password"] # Registry storage configs storage_config = configs.get('storage_service') or {} config_dict['registry_custom_ca_bundle_path'] = storage_config.get( 'ca_bundle') or '' if storage_config.get('filesystem'): config_dict['storage_provider_name'] = 'filesystem' config_dict['storage_provider_config'] = storage_config['filesystem'] elif storage_config.get('azure'): config_dict['storage_provider_name'] = 'azure' config_dict['storage_provider_config'] = storage_config['azure'] elif storage_config.get('gcs'): config_dict['storage_provider_name'] = 'gcs' config_dict['storage_provider_config'] = storage_config['gcs'] elif storage_config.get('s3'): config_dict['storage_provider_name'] = 's3' config_dict['storage_provider_config'] = storage_config['s3'] elif storage_config.get('swift'): config_dict['storage_provider_name'] = 'swift' config_dict['storage_provider_config'] = storage_config['swift'] elif storage_config.get('oss'): config_dict['storage_provider_name'] = 'oss' config_dict['storage_provider_config'] = storage_config['oss'] else: config_dict['storage_provider_name'] = 'filesystem' config_dict['storage_provider_config'] = {} if storage_config.get('redirect'): config_dict['storage_redirect_disabled'] = storage_config['redirect'][ 'disabled'] # Global proxy configs proxy_config = configs.get('proxy') or {} proxy_components = proxy_config.get('components') or [] no_proxy_config = proxy_config.get('no_proxy') all_no_proxy = INTERNAL_NO_PROXY_DN if no_proxy_config: all_no_proxy |= set(no_proxy_config.split(',')) for proxy_component in proxy_components: config_dict[proxy_component + '_http_proxy'] = proxy_config.get('http_proxy') or '' config_dict[proxy_component + '_https_proxy'] = proxy_config.get('https_proxy') or '' config_dict[proxy_component + '_no_proxy'] = ','.join(all_no_proxy) # Trivy configs, optional trivy_configs = configs.get("trivy") or {} config_dict['trivy_github_token'] = trivy_configs.get("github_token") or '' config_dict['trivy_skip_update'] = trivy_configs.get( "skip_update") or False config_dict['trivy_offline_scan'] = trivy_configs.get( "offline_scan") or False config_dict['trivy_ignore_unfixed'] = trivy_configs.get( "ignore_unfixed") or False config_dict['trivy_insecure'] = trivy_configs.get("insecure") or False config_dict['trivy_timeout'] = trivy_configs.get("timeout") or '5m0s' # Chart configs chart_configs = configs.get("chart") or {} if chart_configs.get('absolute_url') == 'enabled': config_dict['chart_absolute_url'] = True else: config_dict['chart_absolute_url'] = False # jobservice config js_config = configs.get('jobservice') or {} config_dict['max_job_workers'] = js_config["max_job_workers"] config_dict['jobservice_secret'] = generate_random_string(16) # notification config notification_config = configs.get('notification') or {} config_dict['notification_webhook_job_max_retry'] = notification_config[ "webhook_job_max_retry"] # Log configs allowed_levels = ['debug', 'info', 'warning', 'error', 'fatal'] log_configs = configs.get('log') or {} log_level = log_configs['level'] if log_level not in allowed_levels: raise Exception( 'log level must be one of debug, info, warning, error, fatal') config_dict['log_level'] = log_level.lower() # parse local log related configs local_logs = log_configs.get('local') or {} if local_logs: config_dict['log_location'] = local_logs.get( 'location') or '/var/log/harbor' config_dict['log_rotate_count'] = local_logs.get('rotate_count') or 50 config_dict['log_rotate_size'] = local_logs.get( 'rotate_size') or '200M' # parse external log endpoint related configs if log_configs.get('external_endpoint'): config_dict['log_external'] = True config_dict['log_ep_protocol'] = log_configs['external_endpoint'][ 'protocol'] config_dict['log_ep_host'] = log_configs['external_endpoint']['host'] config_dict['log_ep_port'] = log_configs['external_endpoint']['port'] else: config_dict['log_external'] = False # external DB, optional, if external_db enabled, it will cover the database config external_db_configs = configs.get('external_database') or {} if external_db_configs: config_dict['external_database'] = True # harbor db config_dict['harbor_db_host'] = external_db_configs['harbor']['host'] config_dict['harbor_db_port'] = external_db_configs['harbor']['port'] config_dict['harbor_db_name'] = external_db_configs['harbor'][ 'db_name'] config_dict['harbor_db_username'] = external_db_configs['harbor'][ 'username'] config_dict['harbor_db_password'] = external_db_configs['harbor'][ 'password'] config_dict['harbor_db_sslmode'] = external_db_configs['harbor'][ 'ssl_mode'] config_dict['harbor_db_max_idle_conns'] = external_db_configs[ 'harbor'].get("max_idle_conns") or default_db_max_idle_conns config_dict['harbor_db_max_open_conns'] = external_db_configs[ 'harbor'].get("max_open_conns") or default_db_max_open_conns if with_notary: # notary signer config_dict['notary_signer_db_host'] = external_db_configs[ 'notary_signer']['host'] config_dict['notary_signer_db_port'] = external_db_configs[ 'notary_signer']['port'] config_dict['notary_signer_db_name'] = external_db_configs[ 'notary_signer']['db_name'] config_dict['notary_signer_db_username'] = external_db_configs[ 'notary_signer']['username'] config_dict['notary_signer_db_password'] = external_db_configs[ 'notary_signer']['password'] config_dict['notary_signer_db_sslmode'] = external_db_configs[ 'notary_signer']['ssl_mode'] # notary server config_dict['notary_server_db_host'] = external_db_configs[ 'notary_server']['host'] config_dict['notary_server_db_port'] = external_db_configs[ 'notary_server']['port'] config_dict['notary_server_db_name'] = external_db_configs[ 'notary_server']['db_name'] config_dict['notary_server_db_username'] = external_db_configs[ 'notary_server']['username'] config_dict['notary_server_db_password'] = external_db_configs[ 'notary_server']['password'] config_dict['notary_server_db_sslmode'] = external_db_configs[ 'notary_server']['ssl_mode'] else: config_dict['external_database'] = False # update redis configs config_dict.update( get_redis_configs(configs.get("external_redis", None), with_trivy)) # auto generated secret string for core config_dict['core_secret'] = generate_random_string(16) # UAA configs config_dict['uaa'] = configs.get('uaa') or {} config_dict['registry_username'] = REGISTRY_USER_NAME config_dict['registry_password'] = generate_random_string(32) internal_tls_config = configs.get('internal_tls') # TLS related configs if internal_tls_config and internal_tls_config.get('enabled'): config_dict['internal_tls'] = InternalTLS( internal_tls_config['enabled'], False, internal_tls_config['dir'], configs['data_volume'], with_notary=with_notary, with_trivy=with_trivy, with_chartmuseum=with_chartmuseum, external_database=config_dict['external_database']) else: config_dict['internal_tls'] = InternalTLS() # metric configs metric_config = configs.get('metric') if metric_config: config_dict['metric'] = Metric(metric_config['enabled'], metric_config['port'], metric_config['path']) else: config_dict['metric'] = Metric() # trace configs trace_config = configs.get('trace') config_dict['trace'] = Trace(trace_config or {}) if config_dict['internal_tls'].enabled: config_dict['portal_url'] = 'https://portal:8443' config_dict['registry_url'] = 'https://registry:5443' config_dict['registry_controller_url'] = 'https://registryctl:8443' config_dict['core_url'] = 'https://core:8443' config_dict['core_local_url'] = 'https://core:8443' config_dict['token_service_url'] = 'https://core:8443/service/token' config_dict['jobservice_url'] = 'https://jobservice:8443' config_dict['trivy_adapter_url'] = 'https://trivy-adapter:8443' # config_dict['notary_url'] = 'http://notary-server:4443' config_dict['chart_repository_url'] = 'https://chartmuseum:9443' # purge upload configs purge_upload_config = configs.get('upload_purging') config_dict['purge_upload'] = PurgeUpload(purge_upload_config or {}) return config_dict
def seed(): metrics = [] Metric.query.delete() metrics.append( Metric(1119, 15008, 'ADA', 0.722873065774081, 0.765547263681592)) metrics.append( Metric(1119, 15008, 'DT', 0.873483256815293, 0.88681592039801)) metrics.append( Metric(1119, 15008, 'KNN', 0.251396648044693, 0.335820895522388)) metrics.append( Metric(1119, 15008, 'LR', 0.713287844475162, 0.758706467661692)) metrics.append( Metric(1119, 15008, 'NN', 0.251396648044693, 0.335820895522388)) metrics.append( Metric(1119, 15008, 'RF', 0.894337665032553, 0.90547263681592)) metrics.append( Metric(1119, 15008, 'SGD', 0.356550580431177, 0.396766169154229)) metrics.append( Metric(1119, 15008, 'SVC', 0.399103139013453, 0.664179104477612)) metrics.append( Metric(1120, 7734, 'ADA', 0.734491931342756, 0.789405684754522)) metrics.append( Metric(1120, 7734, 'DT', 0.910084328079651, 0.921188630490956)) metrics.append( Metric(1120, 7734, 'KNN', 0.241176470588235, 0.317829457364341)) metrics.append( Metric(1120, 7734, 'LR', 0.690322666212778, 0.766149870801034)) metrics.append( Metric(1120, 7734, 'NN', 0.289475084827722, 0.348191214470284)) metrics.append( Metric(1120, 7734, 'RF', 0.917335953520164, 0.928940568475452)) metrics.append( Metric(1120, 7734, 'SGD', 0.244364525401878, 0.319767441860465)) metrics.append( Metric(1120, 7734, 'SVC', 0.405529953917051, 0.682170542635659)) metrics.append( Metric(1121, 8924, 'ADA', 0.715987593917994, 0.782786885245902)) metrics.append( Metric(1121, 8924, 'DT', 0.880103448275862, 0.896174863387978)) metrics.append(Metric(1121, 8924, 'KNN', 0.2375, 0.311475409836066)) metrics.append( Metric(1121, 8924, 'LR', 0.724269971856938, 0.78551912568306)) metrics.append(Metric(1121, 8924, 'NN', 0.2375, 0.311475409836066)) metrics.append( Metric(1121, 8924, 'RF', 0.899531572376053, 0.915300546448087)) metrics.append( Metric(1121, 8924, 'SGD', 0.583455629099404, 0.584699453551913)) metrics.append( Metric(1121, 8924, 'SVC', 0.407766990291262, 0.688524590163934)) metrics.append( Metric(1122, 13273, 'ADA', 0.486842105263158, 0.948717948717949)) metrics.append( Metric(1122, 13273, 'DT', 0.904606604158174, 0.982905982905983)) metrics.append( Metric(1122, 13273, 'KNN', 0.486842105263158, 0.948717948717949)) metrics.append( Metric(1122, 13273, 'LR', 0.75313562302192, 0.961538461538462)) metrics.append( Metric(1122, 13273, 'NN', 0.472769855622424, 0.675213675213675)) metrics.append( Metric(1122, 13273, 'RF', 0.910723531816324, 0.985042735042735)) metrics.append( Metric(1122, 13273, 'SGD', 0.484581497797357, 0.94017094017094)) metrics.append( Metric(1122, 13273, 'SVC', 0.486842105263158, 0.948717948717949)) metrics.append( Metric(1123, 8141, 'ADA', 0.728109101187111, 0.853994490358127)) metrics.append( Metric(1123, 8141, 'DT', 0.895621379683474, 0.934573002754821)) metrics.append( Metric(1123, 8141, 'KNN', 0.444954128440367, 0.801652892561983)) metrics.append( Metric(1123, 8141, 'LR', 0.697321428571428, 0.84435261707989)) metrics.append( Metric(1123, 8141, 'NN', 0.16551724137931, 0.198347107438017)) metrics.append( Metric(1123, 8141, 'RF', 0.906933609127805, 0.944214876033058)) metrics.append( Metric(1123, 8141, 'SGD', 0.22592276674938, 0.242424242424242)) metrics.append( Metric(1123, 8141, 'SVC', 0.444954128440367, 0.801652892561983)) metrics.append( Metric(1124, 10939, 'ADA', 0.822651533446028, 0.843137254901961)) metrics.append( Metric(1124, 10939, 'DT', 0.933326070378037, 0.941176470588235)) metrics.append(Metric(1124, 10939, 'KNN', 0.25, 0.333333333333333)) metrics.append( Metric(1124, 10939, 'LR', 0.820816864295125, 0.843137254901961)) metrics.append(Metric(1124, 10939, 'NN', 0.4, 0.666666666666667)) metrics.append( Metric(1124, 10939, 'RF', 0.931732465065798, 0.939542483660131)) metrics.append( Metric(1124, 10939, 'SGD', 0.271706016755522, 0.34640522875817)) metrics.append(Metric(1124, 10939, 'SVC', 0.4, 0.666666666666667)) metrics.append( Metric(1125, 9305, 'ADA', 0.434782608695652, 0.769230769230769)) metrics.append( Metric(1125, 9305, 'DT', 0.846517119244392, 0.893162393162393)) metrics.append( Metric(1125, 9305, 'KNN', 0.434782608695652, 0.769230769230769)) metrics.append( Metric(1125, 9305, 'LR', 0.434782608695652, 0.769230769230769)) metrics.append(Metric(1125, 9305, 'NN', 0.2525374714121, 0.277777777777778)) metrics.append( Metric(1125, 9305, 'RF', 0.88663967611336, 0.925213675213675)) metrics.append( Metric(1125, 9305, 'SGD', 0.223747426218257, 0.256410256410256)) metrics.append( Metric(1125, 9305, 'SVC', 0.434782608695652, 0.769230769230769)) metrics.append( Metric(1126, 10019, 'ADA', 0.73216077289899, 0.946540880503145)) metrics.append( Metric(1126, 10019, 'DT', 0.87994966442953, 0.971698113207547)) metrics.append( Metric(1126, 10019, 'KNN', 0.482926829268293, 0.933962264150943)) metrics.append( Metric(1126, 10019, 'LR', 0.701925808100892, 0.94811320754717)) metrics.append( Metric(1126, 10019, 'NN', 0.482926829268293, 0.933962264150943)) metrics.append( Metric(1126, 10019, 'RF', 0.900818713450292, 0.977987421383648)) metrics.append( Metric(1126, 10019, 'SGD', 0.695093062605753, 0.919811320754717)) metrics.append( Metric(1126, 10019, 'SVC', 0.482926829268293, 0.933962264150943)) metrics.append( Metric(1129, 8139, 'ADA', 0.708448188413787, 0.758547008547009)) metrics.append( Metric(1129, 8139, 'DT', 0.869614770914064, 0.882478632478633)) metrics.append(Metric(1129, 8139, 'KNN', 0.4, 0.666666666666667)) metrics.append( Metric(1129, 8139, 'LR', 0.686996650373698, 0.743589743589744)) metrics.append(Metric(1129, 8139, 'NN', 0.25, 0.333333333333333)) metrics.append( Metric(1129, 8139, 'RF', 0.878508264075144, 0.892094017094017)) metrics.append( Metric(1129, 8139, 'SGD', 0.350892114979413, 0.386752136752137)) metrics.append(Metric(1129, 8139, 'SVC', 0.4, 0.666666666666667)) metrics.append( Metric(1130, 12883, 'ADA', 0.57747054322347, 0.811063218390805)) metrics.append( Metric(1130, 12883, 'DT', 0.874347856686056, 0.915229885057471)) metrics.append( Metric(1130, 12883, 'KNN', 0.171428571428571, 0.206896551724138)) metrics.append( Metric(1130, 12883, 'LR', 0.596048706311159, 0.802442528735632)) metrics.append( Metric(1130, 12883, 'NN', 0.171428571428571, 0.206896551724138)) metrics.append( Metric(1130, 12883, 'RF', 0.892702980472765, 0.931034482758621)) metrics.append( Metric(1130, 12883, 'SGD', 0.171428571428571, 0.206896551724138)) metrics.append( Metric(1130, 12883, 'SVC', 0.442307692307692, 0.793103448275862)) metrics.append( Metric(1131, 9376, 'ADA', 0.714130168744039, 0.797709923664122)) metrics.append( Metric(1131, 9376, 'DT', 0.875376565720628, 0.896946564885496)) metrics.append( Metric(1131, 9376, 'KNN', 0.415178571428571, 0.709923664122137)) metrics.append( Metric(1131, 9376, 'LR', 0.717394468081464, 0.786259541984733)) metrics.append( Metric(1131, 9376, 'NN', 0.198708140984573, 0.212468193384224)) metrics.append( Metric(1131, 9376, 'RF', 0.899656744401005, 0.91793893129771)) metrics.append( Metric(1131, 9376, 'SGD', 0.300328312743273, 0.330788804071247)) metrics.append( Metric(1131, 9376, 'SVC', 0.415178571428571, 0.709923664122137)) metrics.append( Metric(1132, 9037, 'ADA', 0.628649096382162, 0.922814207650273)) metrics.append( Metric(1132, 9037, 'DT', 0.892488546686024, 0.96448087431694)) metrics.append( Metric(1132, 9037, 'KNN', 0.476394849785408, 0.90983606557377)) metrics.append(Metric(1132, 9037, 'LR', 0.50568801620695, 0.91120218579235)) metrics.append( Metric(1132, 9037, 'NN', 0.476394849785408, 0.90983606557377)) metrics.append( Metric(1132, 9037, 'RF', 0.928099332219125, 0.977459016393443)) metrics.append( Metric(1132, 9037, 'SGD', 0.0946273185615937, 0.100409836065574)) metrics.append( Metric(1132, 9037, 'SVC', 0.502058040192314, 0.758196721311475)) metrics.append( Metric(1133, 9596, 'ADA', 0.777272727272727, 0.876262626262626)) metrics.append( Metric(1133, 9596, 'DT', 0.878559057671376, 0.922979797979798)) metrics.append( Metric(1133, 9596, 'KNN', 0.164556962025316, 0.196969696969697)) metrics.append( Metric(1133, 9596, 'LR', 0.741838902839482, 0.863636363636364)) metrics.append( Metric(1133, 9596, 'NN', 0.164556962025316, 0.196969696969697)) metrics.append( Metric(1133, 9596, 'RF', 0.903269144648455, 0.939393939393939)) metrics.append( Metric(1133, 9596, 'SGD', 0.238381266672613, 0.251262626262626)) metrics.append( Metric(1133, 9596, 'SVC', 0.445378151260504, 0.803030303030303)) metrics.append( Metric(1134, 7072, 'ADA', 0.762954677591694, 0.831039755351682)) metrics.append( Metric(1134, 7072, 'DT', 0.897130915777529, 0.919724770642202)) metrics.append( Metric(1134, 7072, 'KNN', 0.420212765957447, 0.724770642201835)) metrics.append( Metric(1134, 7072, 'LR', 0.761901302390505, 0.829510703363914)) metrics.append( Metric(1134, 7072, 'NN', 0.420212765957447, 0.724770642201835)) metrics.append( Metric(1134, 7072, 'RF', 0.900498831440465, 0.922782874617737)) metrics.append( Metric(1134, 7072, 'SGD', 0.215827338129496, 0.275229357798165)) metrics.append( Metric(1134, 7072, 'SVC', 0.420212765957447, 0.724770642201835)) metrics.append( Metric(1137, 8971, 'ADA', 0.730224185209219, 0.773989898989899)) metrics.append( Metric(1137, 8971, 'DT', 0.878942273398889, 0.890151515151515)) metrics.append( Metric(1137, 8971, 'KNN', 0.258426966292135, 0.348484848484849)) metrics.append( Metric(1137, 8971, 'LR', 0.707521603517922, 0.753787878787879)) metrics.append( Metric(1137, 8971, 'NN', 0.411245269417913, 0.416666666666667)) metrics.append( Metric(1137, 8971, 'RF', 0.883254514522951, 0.892676767676768)) metrics.append( Metric(1137, 8971, 'SGD', 0.661245132072812, 0.662878787878788)) metrics.append( Metric(1137, 8971, 'SVC', 0.394495412844037, 0.651515151515152)) metrics.append( Metric(1139, 4445, 'ADA', 0.810019024817768, 0.824444444444444)) metrics.append( Metric(1139, 4445, 'DT', 0.919308626960274, 0.923333333333333)) metrics.append( Metric(1139, 4445, 'KNN', 0.627049963683627, 0.698888888888889)) metrics.append( Metric(1139, 4445, 'LR', 0.803576086320059, 0.817777777777778)) metrics.append( Metric(1139, 4445, 'NN', 0.271844660194175, 0.373333333333333)) metrics.append(Metric(1139, 4445, 'RF', 0.936260288848436, 0.94)) metrics.append( Metric(1139, 4445, 'SGD', 0.27383468883236, 0.374444444444444)) metrics.append( Metric(1139, 4445, 'SVC', 0.385245901639344, 0.626666666666667)) metrics.append( Metric(1140, 7301, 'ADA', 0.817572470027295, 0.856770833333333)) metrics.append(Metric(1140, 7301, 'DT', 0.907359752959341, 0.921875)) metrics.append(Metric(1140, 7301, 'KNN', 0.228915662650602, 0.296875)) metrics.append( Metric(1140, 7301, 'LR', 0.800849936672646, 0.842447916666667)) metrics.append(Metric(1140, 7301, 'NN', 0.228915662650602, 0.296875)) metrics.append( Metric(1140, 7301, 'RF', 0.917850824865265, 0.932291666666667)) metrics.append( Metric(1140, 7301, 'SGD', 0.26420166842738, 0.315104166666667)) metrics.append(Metric(1140, 7301, 'SVC', 0.412844036697248, 0.703125)) metrics.append( Metric(1142, 8480, 'ADA', 0.743133067729084, 0.789954337899543)) metrics.append( Metric(1142, 8480, 'DT', 0.911142282478278, 0.920091324200913)) metrics.append( Metric(1142, 8480, 'KNN', 0.396694214876033, 0.657534246575342)) metrics.append( Metric(1142, 8480, 'LR', 0.741801207863141, 0.776255707762557)) metrics.append( Metric(1142, 8480, 'NN', 0.396694214876033, 0.657534246575342)) metrics.append( Metric(1142, 8480, 'RF', 0.907259239922557, 0.916666666666667)) metrics.append( Metric(1142, 8480, 'SGD', 0.360978755027103, 0.39041095890411)) metrics.append( Metric(1142, 8480, 'SVC', 0.396694214876033, 0.657534246575342)) metrics.append( Metric(1143, 8575, 'ADA', 0.722093561834183, 0.884259259259259)) metrics.append( Metric(1143, 8575, 'DT', 0.851335656213705, 0.925925925925926)) metrics.append( Metric(1143, 8575, 'KNN', 0.142857142857143, 0.166666666666667)) metrics.append( Metric(1143, 8575, 'LR', 0.617948532076839, 0.858796296296296)) metrics.append( Metric(1143, 8575, 'NN', 0.142857142857143, 0.166666666666667)) metrics.append(Metric(1143, 8575, 'RF', 0.870260169293572, 0.9375)) metrics.append( Metric(1143, 8575, 'SGD', 0.142857142857143, 0.166666666666667)) metrics.append( Metric(1143, 8575, 'SVC', 0.454545454545455, 0.833333333333333)) metrics.append( Metric(1144, 10379, 'ADA', 0.707197643503376, 0.798689138576779)) metrics.append( Metric(1144, 10379, 'DT', 0.877516172741444, 0.898876404494382)) metrics.append( Metric(1144, 10379, 'KNN', 0.219298245614035, 0.280898876404494)) metrics.append( Metric(1144, 10379, 'LR', 0.677736264447826, 0.781835205992509)) metrics.append( Metric(1144, 10379, 'NN', 0.219298245614035, 0.280898876404494)) metrics.append( Metric(1144, 10379, 'RF', 0.900160899541717, 0.920411985018727)) metrics.append( Metric(1144, 10379, 'SGD', 0.219298245614035, 0.280898876404494)) metrics.append( Metric(1144, 10379, 'SVC', 0.418300653594771, 0.719101123595506)) metrics.append( Metric(1146, 8844, 'ADA', 0.683493760665529, 0.813725490196078)) metrics.append( Metric(1146, 8844, 'DT', 0.890423572744015, 0.920168067226891)) metrics.append( Metric(1146, 8844, 'KNN', 0.430622009569378, 0.756302521008403)) metrics.append( Metric(1146, 8844, 'LR', 0.665465097825841, 0.804621848739496)) metrics.append( Metric(1146, 8844, 'NN', 0.430622009569378, 0.756302521008403)) metrics.append( Metric(1146, 8844, 'RF', 0.899926347726673, 0.928571428571429)) metrics.append( Metric(1146, 8844, 'SGD', 0.195945945945946, 0.243697478991597)) metrics.append( Metric(1146, 8844, 'SVC', 0.430622009569378, 0.756302521008403)) metrics.append( Metric(1147, 9537, 'ADA', 0.636203606212161, 0.690476190476191)) metrics.append( Metric(1147, 9537, 'DT', 0.859539120631342, 0.863756613756614)) metrics.append( Metric(1147, 9537, 'KNN', 0.526311488063347, 0.634920634920635)) metrics.append( Metric(1147, 9537, 'LR', 0.661839530332681, 0.703703703703704)) metrics.append( Metric(1147, 9537, 'NN', 0.572003218020917, 0.623015873015873)) metrics.append( Metric(1147, 9537, 'RF', 0.875163086772143, 0.87962962962963)) metrics.append( Metric(1147, 9537, 'SGD', 0.643857882623705, 0.653439153439153)) metrics.append( Metric(1147, 9537, 'SVC', 0.376237623762376, 0.603174603174603)) metrics.append( Metric(1148, 6532, 'ADA', 0.802081288042411, 0.830357142857143)) metrics.append( Metric(1148, 6532, 'DT', 0.907434841824706, 0.91765873015873)) metrics.append(Metric(1148, 6532, 'KNN', 0.664, 0.744047619047619)) metrics.append( Metric(1148, 6532, 'LR', 0.786884255623656, 0.819444444444444)) metrics.append(Metric(1148, 6532, 'NN', 0.4, 0.666666666666667)) metrics.append( Metric(1148, 6532, 'RF', 0.92516745245126, 0.933531746031746)) metrics.append( Metric(1148, 6532, 'SGD', 0.546951971811925, 0.548611111111111)) metrics.append(Metric(1148, 6532, 'SVC', 0.4, 0.666666666666667)) metrics.append(Metric(1204, 11792, 'ADA', 0.735483752456878, 0.859375)) metrics.append(Metric(1204, 11792, 'DT', 0.873046875, 0.91875)) metrics.append(Metric(1204, 11792, 'KNN', 0.444444444444444, 0.8)) metrics.append(Metric(1204, 11792, 'LR', 0.677674851062364, 0.8375)) metrics.append(Metric(1204, 11792, 'NN', 0.166666666666667, 0.2)) metrics.append( Metric(1204, 11792, 'RF', 0.882339757956073, 0.927083333333333)) metrics.append(Metric(1204, 11792, 'SGD', 0.166666666666667, 0.2)) metrics.append( Metric(1204, 11792, 'SVC', 0.449883142170525, 0.801041666666667)) metrics.append( Metric(1205, 9835, 'ADA', 0.702123026673925, 0.709722222222222)) metrics.append( Metric(1205, 9835, 'DT', 0.890354823972423, 0.893055555555556)) metrics.append( Metric(1205, 9835, 'KNN', 0.368421052631579, 0.583333333333333)) metrics.append( Metric(1205, 9835, 'LR', 0.675226295828066, 0.690277777777778)) metrics.append( Metric(1205, 9835, 'NN', 0.345095693779904, 0.391666666666667)) metrics.append( Metric(1205, 9835, 'RF', 0.891324208168162, 0.894444444444444)) metrics.append(Metric(1205, 9835, 'SGD', 0.412001797927319, 0.4625)) metrics.append( Metric(1205, 9835, 'SVC', 0.368421052631579, 0.583333333333333)) metrics.append( Metric(1206, 8091, 'ADA', 0.546732716544037, 0.850490196078431)) metrics.append( Metric(1206, 8091, 'DT', 0.889705882352941, 0.938725490196078)) metrics.append(Metric(1206, 8091, 'KNN', 0.456, 0.838235294117647)) metrics.append( Metric(1206, 8091, 'LR', 0.669490080154625, 0.860294117647059)) metrics.append(Metric(1206, 8091, 'NN', 0.456, 0.838235294117647)) metrics.append( Metric(1206, 8091, 'RF', 0.910835058661146, 0.95343137254902)) metrics.append( Metric(1206, 8091, 'SGD', 0.675973164960256, 0.790441176470588)) metrics.append(Metric(1206, 8091, 'SVC', 0.456, 0.838235294117647)) metrics.append( Metric(1207, 7476, 'ADA', 0.764536110041747, 0.826822916666667)) metrics.append(Metric(1207, 7476, 'DT', 0.914001327140013, 0.9296875)) metrics.append(Metric(1207, 7476, 'KNN', 0.219512195121951, 0.28125)) metrics.append( Metric(1207, 7476, 'LR', 0.740433496572445, 0.811197916666667)) metrics.append(Metric(1207, 7476, 'NN', 0.219512195121951, 0.28125)) metrics.append(Metric(1207, 7476, 'RF', 0.908082854773178, 0.92578125)) metrics.append( Metric(1207, 7476, 'SGD', 0.738195655620739, 0.776041666666667)) metrics.append( Metric(1207, 7476, 'SVC', 0.42218200351567, 0.717447916666667)) metrics.append( Metric(1208, 7929, 'ADA', 0.638433632344535, 0.945767195767196)) metrics.append( Metric(1208, 7929, 'DT', 0.869112494332001, 0.972222222222222)) metrics.append( Metric(1208, 7929, 'KNN', 0.483606557377049, 0.936507936507936)) metrics.append( Metric(1208, 7929, 'LR', 0.710144927536232, 0.953703703703704)) metrics.append( Metric(1208, 7929, 'NN', 0.483606557377049, 0.936507936507936)) metrics.append(Metric(1208, 7929, 'RF', 0.8330491930711, 0.966931216931217)) metrics.append( Metric(1208, 7929, 'SGD', 0.635643293828341, 0.832010582010582)) metrics.append( Metric(1208, 7929, 'SVC', 0.483606557377049, 0.936507936507936)) metrics.append( Metric(1211, 8732, 'ADA', 0.709922125779102, 0.710858585858586)) metrics.append( Metric(1211, 8732, 'DT', 0.877382747970983, 0.877525252525252)) metrics.append( Metric(1211, 8732, 'KNN', 0.326530612244898, 0.484848484848485)) metrics.append( Metric(1211, 8732, 'LR', 0.719552110249785, 0.71969696969697)) metrics.append( Metric(1211, 8732, 'NN', 0.326530612244898, 0.484848484848485)) metrics.append( Metric(1211, 8732, 'RF', 0.896172661870503, 0.896464646464647)) metrics.append( Metric(1211, 8732, 'SGD', 0.376389313394287, 0.508838383838384)) metrics.append(Metric(1211, 8732, 'SVC', 0.34, 0.515151515151515)) metrics.append( Metric(1212, 5902, 'ADA', 0.69055241372502, 0.871980676328502)) metrics.append( Metric(1212, 5902, 'DT', 0.880626809062781, 0.93719806763285)) metrics.append( Metric(1212, 5902, 'KNN', 0.452380952380952, 0.826086956521739)) metrics.append( Metric(1212, 5902, 'LR', 0.667063976448625, 0.864734299516908)) metrics.append( Metric(1212, 5902, 'NN', 0.452380952380952, 0.826086956521739)) metrics.append( Metric(1212, 5902, 'RF', 0.875561100792559, 0.935990338164251)) metrics.append( Metric(1212, 5902, 'SGD', 0.30917471338137, 0.309178743961353)) metrics.append( Metric(1212, 5902, 'SVC', 0.452380952380952, 0.826086956521739)) metrics.append( Metric(1213, 8975, 'ADA', 0.597032933374173, 0.743489583333333)) metrics.append( Metric(1213, 8975, 'DT', 0.859952506131381, 0.884114583333333)) metrics.append(Metric(1213, 8975, 'KNN', 0.412844036697248, 0.703125)) metrics.append(Metric(1213, 8975, 'LR', 0.645277725507638, 0.75390625)) metrics.append(Metric(1213, 8975, 'NN', 0.412844036697248, 0.703125)) metrics.append( Metric(1213, 8975, 'RF', 0.880837359098229, 0.903645833333333)) metrics.append(Metric(1213, 8975, 'SGD', 0.646082949308756, 0.71875)) metrics.append(Metric(1213, 8975, 'SVC', 0.412844036697248, 0.703125)) metrics.append( Metric(1214, 6579, 'ADA', 0.651451310099791, 0.880801687763713)) metrics.append( Metric(1214, 6579, 'DT', 0.902186341210732, 0.94831223628692)) metrics.append( Metric(1214, 6579, 'KNN', 0.131868131868132, 0.151898734177215)) metrics.append( Metric(1214, 6579, 'LR', 0.640129003856718, 0.874472573839662)) metrics.append( Metric(1214, 6579, 'NN', 0.131868131868132, 0.151898734177215)) metrics.append( Metric(1214, 6579, 'RF', 0.934469510305198, 0.967299578059072)) metrics.append( Metric(1214, 6579, 'SGD', 0.20679230489205, 0.212025316455696)) metrics.append( Metric(1214, 6579, 'SVC', 0.458904109589041, 0.848101265822785)) metrics.append( Metric(1215, 8256, 'ADA', 0.922398589065256, 0.977272727272727)) metrics.append( Metric(1215, 8256, 'DT', 0.816666666666667, 0.939393939393939)) metrics.append( Metric(1215, 8256, 'KNN', 0.476190476190476, 0.909090909090909)) metrics.append(Metric(1215, 8256, 'LR', 0.472, 0.893939393939394)) metrics.append( Metric(1215, 8256, 'NN', 0.476190476190476, 0.909090909090909)) metrics.append( Metric(1215, 8256, 'RF', 0.891803278688525, 0.96969696969697)) metrics.append(Metric(1215, 8256, 'SGD', 0.472, 0.893939393939394)) metrics.append( Metric(1215, 8256, 'SVC', 0.476190476190476, 0.909090909090909)) metrics.append(Metric(1216, 7038, 'ADA', 0.782370233864245, 0.80625)) metrics.append( Metric(1216, 7038, 'DT', 0.89939227944077, 0.907291666666667)) metrics.append(Metric(1216, 7038, 'KNN', 0.259259259259259, 0.35)) metrics.append( Metric(1216, 7038, 'LR', 0.762831845609316, 0.786458333333333)) metrics.append(Metric(1216, 7038, 'NN', 0.259259259259259, 0.35)) metrics.append( Metric(1216, 7038, 'RF', 0.917052425754938, 0.923958333333333)) metrics.append( Metric(1216, 7038, 'SGD', 0.393403260457475, 0.416666666666667)) metrics.append(Metric(1216, 7038, 'SVC', 0.393939393939394, 0.65)) metrics.append( Metric(1220, 8772, 'ADA', 0.746271215498028, 0.746621621621622)) metrics.append( Metric(1220, 8772, 'DT', 0.914072685788787, 0.914414414414414)) metrics.append( Metric(1220, 8772, 'KNN', 0.314814814814815, 0.45945945945946)) metrics.append( Metric(1220, 8772, 'LR', 0.731322335903017, 0.731981981981982)) metrics.append( Metric(1220, 8772, 'NN', 0.314814814814815, 0.45945945945946)) metrics.append( Metric(1220, 8772, 'RF', 0.885003885003885, 0.885135135135135)) metrics.append( Metric(1220, 8772, 'SGD', 0.314814814814815, 0.45945945945946)) metrics.append( Metric(1220, 8772, 'SVC', 0.350877192982456, 0.540540540540541)) metrics.append(Metric(1221, 10835, 'ADA', 0.482012997994733, 0.790625)) metrics.append( Metric(1221, 10835, 'DT', 0.875032749526677, 0.917708333333333)) metrics.append(Metric(1221, 10835, 'KNN', 0.440559440559441, 0.7875)) metrics.append(Metric(1221, 10835, 'LR', 0.495750167128259, 0.79375)) metrics.append(Metric(1221, 10835, 'NN', 0.440559440559441, 0.7875)) metrics.append(Metric(1221, 10835, 'RF', 0.861651534803286, 0.9125)) metrics.append(Metric(1221, 10835, 'SGD', 0.591639163916392, 0.728125)) metrics.append(Metric(1221, 10835, 'SVC', 0.440559440559441, 0.7875)) metrics.append( Metric(1222, 8725, 'ADA', 0.65089371589643, 0.758974358974359)) metrics.append( Metric(1222, 8725, 'DT', 0.859186503488596, 0.883333333333333)) metrics.append( Metric(1222, 8725, 'KNN', 0.26120218579235, 0.283333333333333)) metrics.append( Metric(1222, 8725, 'LR', 0.624999094025643, 0.744871794871795)) metrics.append( Metric(1222, 8725, 'NN', 0.414414414414414, 0.707692307692308)) metrics.append( Metric(1222, 8725, 'RF', 0.86836797694999, 0.894871794871795)) metrics.append( Metric(1222, 8725, 'SGD', 0.516627736290398, 0.516666666666667)) metrics.append( Metric(1222, 8725, 'SVC', 0.414414414414414, 0.707692307692308)) metrics.append( Metric(1223, 9147, 'ADA', 0.854340588988476, 0.965189873417722)) metrics.append( Metric(1223, 9147, 'DT', 0.90745200130166, 0.974683544303797)) metrics.append( Metric(1223, 9147, 'KNN', 0.480263157894737, 0.924050632911392)) metrics.append( Metric(1223, 9147, 'LR', 0.816497004650609, 0.958860759493671)) metrics.append( Metric(1223, 9147, 'NN', 0.0873009136194071, 0.0907172995780591)) metrics.append( Metric(1223, 9147, 'RF', 0.943001443001443, 0.985232067510548)) metrics.append( Metric(1223, 9147, 'SGD', 0.655773420479303, 0.892405063291139)) metrics.append( Metric(1223, 9147, 'SVC', 0.480263157894737, 0.924050632911392)) metrics.append( Metric(1224, 8468, 'ADA', 0.72039721750407, 0.809210526315789)) metrics.append( Metric(1224, 8468, 'DT', 0.896547812606345, 0.917763157894737)) metrics.append( Metric(1224, 8468, 'KNN', 0.419847328244275, 0.723684210526316)) metrics.append( Metric(1224, 8468, 'LR', 0.666082761393332, 0.776315789473684)) metrics.append( Metric(1224, 8468, 'NN', 0.22461651586021, 0.269736842105263)) metrics.append( Metric(1224, 8468, 'RF', 0.886626960086232, 0.913377192982456)) metrics.append( Metric(1224, 8468, 'SGD', 0.231634732980024, 0.286184210526316)) metrics.append( Metric(1224, 8468, 'SVC', 0.419847328244275, 0.723684210526316)) metrics.append( Metric(1225, 9213, 'ADA', 0.486486486486487, 0.947368421052632)) metrics.append( Metric(1225, 9213, 'DT', 0.872296124927704, 0.974780701754386)) metrics.append( Metric(1225, 9213, 'KNN', 0.486486486486487, 0.947368421052632)) metrics.append( Metric(1225, 9213, 'LR', 0.635878660199288, 0.948464912280702)) metrics.append( Metric(1225, 9213, 'NN', 0.486486486486487, 0.947368421052632)) metrics.append( Metric(1225, 9213, 'RF', 0.887782922643526, 0.979166666666667)) metrics.append( Metric(1225, 9213, 'SGD', 0.547376570781967, 0.917763157894737)) metrics.append( Metric(1225, 9213, 'SVC', 0.486486486486487, 0.947368421052632)) metrics.append(Metric(1226, 7950, 'ADA', 0.448275862068966, 0.8125)) metrics.append( Metric(1226, 7950, 'DT', 0.853462397617275, 0.914583333333333)) metrics.append(Metric(1226, 7950, 'KNN', 0.448275862068966, 0.8125)) metrics.append(Metric(1226, 7950, 'LR', 0.448275862068966, 0.8125)) metrics.append(Metric(1226, 7950, 'NN', 0.448275862068966, 0.8125)) metrics.append(Metric(1226, 7950, 'RF', 0.868980863373387, 0.928125)) metrics.append( Metric(1226, 7950, 'SGD', 0.58023995429442, 0.701041666666667)) metrics.append( Metric(1226, 7950, 'SVC', 0.490989010989011, 0.597916666666667)) metrics.append( Metric(1228, 8813, 'ADA', 0.744458874923524, 0.838541666666667)) metrics.append(Metric(1228, 8813, 'DT', 0.864110265228162, 0.8984375)) metrics.append( Metric(1228, 8813, 'KNN', 0.189192568154193, 0.208333333333333)) metrics.append( Metric(1228, 8813, 'LR', 0.699244755244755, 0.817708333333333)) metrics.append(Metric(1228, 8813, 'NN', 0.189873417721519, 0.234375)) metrics.append( Metric(1228, 8813, 'RF', 0.888384652889772, 0.919270833333333)) metrics.append( Metric(1228, 8813, 'SGD', 0.672631710674509, 0.716145833333333)) metrics.append(Metric(1228, 8813, 'SVC', 0.433628318584071, 0.765625)) metrics.append( Metric(1234, 9044, 'ADA', 0.575018519573765, 0.755411255411255)) metrics.append( Metric(1234, 9044, 'DT', 0.883985447504368, 0.91017316017316)) metrics.append( Metric(1234, 9044, 'KNN', 0.421052631578947, 0.727272727272727)) metrics.append( Metric(1234, 9044, 'LR', 0.630886970172684, 0.753246753246753)) metrics.append( Metric(1234, 9044, 'NN', 0.421052631578947, 0.727272727272727)) metrics.append( Metric(1234, 9044, 'RF', 0.885836547733848, 0.911255411255411)) metrics.append( Metric(1234, 9044, 'SGD', 0.214285714285714, 0.272727272727273)) metrics.append( Metric(1234, 9044, 'SVC', 0.421052631578947, 0.727272727272727)) metrics.append( Metric(1315, 9443, 'ADA', 0.745218683084002, 0.784825870646766)) metrics.append( Metric(1315, 9443, 'DT', 0.897362851479827, 0.90547263681592)) metrics.append( Metric(1315, 9443, 'KNN', 0.390909090909091, 0.641791044776119)) metrics.append(Metric(1315, 9443, 'LR', 0.76243783075102, 0.79228855721393)) metrics.append( Metric(1315, 9443, 'NN', 0.263736263736264, 0.358208955223881)) metrics.append( Metric(1315, 9443, 'RF', 0.905608479806789, 0.912935323383085)) metrics.append( Metric(1315, 9443, 'SGD', 0.406298221795424, 0.445273631840796)) metrics.append( Metric(1315, 9443, 'SVC', 0.390909090909091, 0.641791044776119)) [db.session.add(metric) for metric in metrics] db.session.commit()
gz.write(reportContents.encode("UTF-8")) gz.close() # so just compress into a memory buffer and save that. report.upload.save(filename, ContentFile(str_io.getvalue())) report.save() for name in metrics: metric = metrics[name] description = metric['description'] units = metric['units'] value = metric['value'] storedMetric = Metric(name=name, description=description, units=units, report=report, value=value) storedMetric.save() return HttpResponse("Report upload succeeded", 'text/plain; charset=UTF-8"', 200) def system_view(request, system_name): try: system = System.objects.get(name=system_name) except System.DoesNotExist: raise Http404 reports = Report.objects.filter(system=system).order_by('-date')[0:5]
# so just compress into a memory buffer and save that. report.upload.save(filename, ContentFile(str_io.getvalue())) report.save() for name in metrics: metric = metrics[name] description = metric['description'] units = metric['units'] value = metric['value'] storedMetric = Metric(name=name, description=description, units=units, report=report, value=value) storedMetric.save() return HttpResponse("Report upload succeeded", 'text/plain; charset=UTF-8"', 200) def system_view(request, system_name): try: system = System.objects.get(name=system_name) except System.DoesNotExist: raise Http404 reports = Report.objects.filter(system=system).order_by('-date')[0:5] report_table = ReportTable()
def record_metric(event_name, request, language='', registration_id=''): if 'From' in request.POST: Metric(event=event_name, phone=request.POST['From'], language=language, registration_id=registration_id).save()