import urllib import ConfigParser import json import config import encoder job_id = 'entity/text/medical/job/19' sentence_clusters = {} api_param = urllib.urlencode({ 'field[job_id]': job_id, 'field[documentType]': 'annotation' }) api_call = urllib.urlopen(config.server + "?" + api_param) response = json.JSONDecoder().decode(api_call.read()) for annotation in response: sentence_id = annotation['unit_id'] if sentence_id in sentence_clusters.keys(): for key in sentence_clusters[sentence_id].keys(): sentence_clusters[sentence_id][key] += annotation['dictionary'][ key] else: sentence_clusters[sentence_id] = annotation['dictionary'] encoder.c_make_encoder = None f = encoder.JSONEncoder().encode(sentence_clusters) print(f)
from enum import Enum import json import encoder from Metrics.WorkerMetrics.Worker import * from Metrics.WorkerMetrics.WorkerMetricsEnum import * # s = Worker(sentence_id="/crowdagent/cf/19935135", # jobs_dict={"entity/text/medical/job/4": ["/crowdagent/cf/19935135","/crowdagent/amt/A1M46I0H8KNEEX"], # "entity/text/medical/job/5": []}, filtered=False) s = Worker("/crowdagent/cf/19935135", ["entity/text/medical/job/4" ], True) print(s.get_unit_clusters()) print(s.get_ann_per_unit()) print(s.get_other_workers()) print(s.get_worker_cosine()) print(s.get_avg_worker_agreement()) encoder.c_make_encoder = None f = encoder.JSONEncoder().encode({WorkerMetricsEnum.worker_cosine:s.get_unit_clusters()}) print(f) #res = s.get_metrics(WorkerMetricsEnum.no_of_sent) #print(s.get_no_annotators())
def get_id(login): bson = mydb.company.find_one({'login': login}, {'_id': 1})['_id'] json = encoder.JSONEncoder().encode(bson) return json
def get_profile(user, test): bson_profile = mydb.profile.find_one({"user": user, "test": test}, {"_id": 0, "test": 1, "result": 1}) json_profile = encoder.JSONEncoder().encode(bson_profile) return json_profile
def get_users(): bson_users = list(mydb.user.find()) json_users = encoder.JSONEncoder().encode(bson_users) return json_users
def get_answer(user, test): bson_answer = list( mydb.answer.find({'test': test, 'user': user}, {'_id': 0, 'number': 1, 'answer': 1}).sort('number', 1)) json_answer = encoder.JSONEncoder().encode(bson_answer) return json_answer
import cherrypy import pymysql import pymysql.cursors import json import datetime import encoder import hashlib import configparser json_encoder = encoder.JSONEncoder() def json_handler(*args, **kwargs): # Adapted from cherrypy/lib/jsontools.py value = cherrypy.serving.request._json_inner_handler(*args, **kwargs) return json_encoder.iterencode(value) def CORS(): cherrypy.response.headers["Access-Control-Allow-Origin"] = "http://localhost" def error(status,message): cherrypy.response.status = status return {"error": message} def read_config(): config = configparser.ConfigParser() config.read('sql_config.ini') return config @cherrypy.popargs('token', 'poll_id') @cherrypy.tools.json_out()