def event_stats_ajax(request): # {{{ DELETE print(request.POST) class_id = request.POST.get("class_id") station = request.POST.get("station", "ntv") jerne = request.POST.get("jerne", "mean_scr") filt = {} filt['cm_ex'] = int(request.POST.get("exclude_cm", "0")) filt['start_ex'] = int(request.POST.get("exclude_start", "0")) filt['cm'] = int(request.POST.get("cm", "0")) filt['start'] = int(request.POST.get("start", "0")) filt['dur'] = int(request.POST.get("dur", "1440")) filt['cate'] = request.POST.get("cate", "") filt['divi'] = request.POST.get("divi", "") print(filt) # st = Stats(station) # フィルターまとめてcalc_stats_with_filterに渡す # -> テキスト読んでフィルタ処理してindexを得る→相関係数計算 ev_file = 'data/evlist/event_1up.txt' feat_file = 'data/feats_web_event_1up.mat' # cache_fn='%s_%s_%d_%d_%d_%d_%s' % (ev_file,feat_file,exclude_cm,exclude_start,start,dur,cate) cache_fn='%s_%s' % (ev_file,feat_file) for k in filt: cache_fn += "_" + str(filt[k]) # cache_fn='%s_%d_%d_%d_%d_%s'%(station,exclude_cm,exclude_start,start,dur,cate) print(cache_fn) # st = load_cache(cache_fn) st = False print(st) if not st: print("Load") st = EventStats(ev_file, feat_file) # st = Stats(station, False) st.calc_stats_with_filter(filt) save_cache(cache_fn, st) num = 100 params = {'class_id':class_id, 'station': station, 'base': 'http://per900c.hpc.vpl.nii.ac.jp/users/hinami/capture/%s/' % station} if class_id is not None and class_id.isdigit(): if jerne == 'hsv' and int(class_id) >= 4: jerne = 'emo' class_id = int(class_id) - 3 else: class_id = int(class_id) params['epg'] = st.get_sorted_samples(class_id, jerne)[:num] params['epg'] = params['epg'][0:300] else: params['epg'] = [] params['summary'] = st.get_summary() return render_json_response(params)
def event_stats_ajax3(request): ## 入力処理 {{{ print(request.POST) class_id = request.POST.get("class_id") station = request.POST.get("station", "ntv") jerne = request.POST.get("jerne", "mean_scr") decrease = int(request.POST.get("decrease", "0")) sort = int(request.POST.get("sort", "0")) sortkey = "target" if sort<=2 else ("rating" if sort<=4 else "date") sortrev = sort<=1 or sort==3 filt = {} filt['cm_ex'] = int(request.POST.get("exclude_cm", "0")) filt['start_ex'] = int(request.POST.get("exclude_start", "0")) filt['cm'] = int(request.POST.get("cm_transition", "0")) filt['start'] = int(request.POST.get("start", "0")) filt['dur'] = int(request.POST.get("dur", "1440")) filt['month'] = int(request.POST.get("month", "0")) filt['cate'] = request.POST.get("cate", "") filt['divi'] = request.POST.get("divi", "") filt['thr'] = [] filt['thr'] = json.loads(request.POST.get("thr","[]")) # filt['thr'] = [{'jerne':'color', 'id':1, 'thr':0.5, 'up':False}] # filt['thr'] = [{'jerne':'big_scr', 'id':7, 'thr':0.3, 'up':True}] print(filt) params = {'class_id':class_id, 'station': station, 'base': 'http://%s/users/hinami/capture/%s/' % (sett.cfg.TVHOST, station)} # params = {'class_id':class_id, 'station': station, 'base': 'http://157.1.160.14/users/hinami/capture/%s/' % station} # }}} ## Filterで絞り込んでStatsを計算 idf = 'event_07up' # idf = 'event_1down' idf_base = 'event_09down' # idf_base = 'sample_list' fns = gen_file_names(idf, idf_base, filt) print(fns['cache_fn']) st = load_cache(fns['cache_fn']) st_base = load_cache(fns['cache_fn_base']) # st = False print(st) if not st: st = EventStats(fns['ev_file'], fns['feat_file']) st.gen_filter_mask(filt) st.calc_stats() save_cache(fns['cache_fn'], st) if not st_base: st_base = EventStats(fns['ev_file_base'], fns['feat_file_base']) st_base.gen_filter_mask(filt) st_base.calc_stats() save_cache(fns['cache_fn_base'], st_base) ## 特徴の詳細を取得 num = 200 if class_id is not None and class_id.isdigit(): if jerne == 'hsv' and int(class_id) >= 4: jerne = 'emo' class_id = int(class_id) - 3 else: class_id = int(class_id) if decrease: params['epg'] = st_base.get_sorted_samples(class_id, jerne, sortkey, sortrev)[:num] params['detail'] = st_base.get_feature_detail(class_id, jerne, st) else: params['epg'] = st.get_sorted_samples(class_id, jerne, sortkey, sortrev)[:num] params['detail'] = st.get_feature_detail(class_id, jerne, st_base) params['epg'] = params['epg'][0:num] else: params['epg'] = [] if decrease: params['summary'] = st_base.get_summary(st) else: params['summary'] = st.get_summary(st_base) return render_json_response(params)