_ce.py 1.1 KB
Newer Older
R
add ce  
root 已提交
1 2 3 4 5 6 7 8 9 10 11
### This file is only used for continuous evaluation test!
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import os
import sys
sys.path.append(os.environ['ceroot'])
from kpi import CostKpi

train_cost_kpi = CostKpi('train_cost', 0.02, 0, actived=True, desc='train cost')
test_cost_kpi = CostKpi('test_cost', 0.02, 0, actived=True, desc='test cost')
12 13
tracking_kpis = [train_cost_kpi, test_cost_kpi]

R
add ce  
root 已提交
14 15 16 17 18

def parse_log(log):
    for line in log.split('\n'):
        fs = line.strip().split('\t')
        print(fs)
19 20 21 22 23 24 25
        if len(fs) == 3 and fs[0] == 'kpis':
            print("-----%s" % fs)
            kpi_name = fs[1]
            kpi_value = float(fs[2])
            yield kpi_name, kpi_value


R
add ce  
root 已提交
26 27 28
def log_to_ce(log):
    kpi_tracker = {}
    for kpi in tracking_kpis:
29 30
        kpi_tracker[kpi.name] = kpi

R
add ce  
root 已提交
31
    for (kpi_name, kpi_value) in parse_log(log):
32 33 34
        print(kpi_name, kpi_value)
        kpi_tracker[kpi_name].add_record(kpi_value)
        kpi_tracker[kpi_name].persist()
R
add ce  
root 已提交
35 36


37 38 39
if __name__ == '__main__':
    log = sys.stdin.read()
    log_to_ce(log)