def encode(self, features, to_string=True, **kwargs): """ Encode a list of features to a JSON object or string. to_string determines whethr it should convert the result to a string or leave it as an object to be encoded later """ results = [] result_data = None for feature in features: data = self.encode_feature(feature) for key,value in data['properties'].items(): if value and isinstance(value, str): data['properties'][key] = unicode(value,"utf-8") results.append(data) result_data = { 'type':'FeatureCollection', 'features': results, 'crs': self.crs } if to_string: result = json_dumps(result_data) else: result = result_data return result
def experiment_statistics(database, experiment_id): db = models.get_database(database) or abort(404) exp = db.session.query(db.Experiment).get(experiment_id) or abort(404) total_time = db.session.query(func.sum(db.ExperimentResult.resultTime)).filter_by(experiment=exp).first()[0] return json_dumps({ 'total_time': total_time, 'total_time_hours': total_time / 60 / 60, })
def get_experiment_results(database, experiment_id): db = models.get_database(database) or abort(404) exp = db.session.query(db.Experiment).get(experiment_id) or abort(404) results = db.session.query(db.ExperimentResult).filter_by(experiment=exp).all() return json_dumps({ "experiment_id": experiment_id, "results": [j.to_json() for j in results] })
def get_experiment_results(database, experiment_id): db = models.get_database(database) or abort(404) exp = db.session.query(db.Experiment).get(experiment_id) or abort(404) results = db.session.query( db.ExperimentResult).filter_by(experiment=exp).all() return json_dumps({ "experiment_id": experiment_id, "results": [j.to_json() for j in results] })
def experiment_statistics(database, experiment_id): db = models.get_database(database) or abort(404) exp = db.session.query(db.Experiment).get(experiment_id) or abort(404) total_time = db.session.query(func.sum( db.ExperimentResult.resultTime)).filter_by(experiment=exp).first()[0] return json_dumps({ 'total_time': total_time, 'total_time_hours': total_time / 60 / 60, })
def statistics(database): db = models.get_database(database) or abort(404) jobs_running = db.session.query(db.ExperimentResult).filter_by(status=0).count() total_time = db.session.query(func.sum(db.ExperimentResult.resultTime)).first()[0] return json_dumps({ 'jobs_running': jobs_running, 'total_time': total_time, 'total_time_days': total_time / 60 / 60 / 24, })
def statistics(database): db = models.get_database(database) or abort(404) jobs_running = db.session.query( db.ExperimentResult).filter_by(status=0).count() total_time = db.session.query(func.sum( db.ExperimentResult.resultTime)).first()[0] return json_dumps({ 'jobs_running': jobs_running, 'total_time': total_time, 'total_time_days': total_time / 60 / 60 / 24, })
def borg_explorer_data(database, experiment_id): db = models.get_database(database) or abort(404) experiment = db.session.query(db.Experiment).get(experiment_id) or abort(404) type = request.args.get('type') if type == 'categories.json': return json_dumps([{"path": experiment.name, "name": experiment.name}]) last_modified_job = db.session.query(func.max(db.ExperimentResult.date_modified))\ .filter_by(experiment=experiment).first() job_count = db.session.query(db.ExperimentResult).filter_by(experiment=experiment).count() @synchronized @cache.memoize(7*24*60*60) def get_data(database, experiment_id, job_count, last_modified_job): runs = db.session.query(db.ExperimentResult) \ .filter(db.ExperimentResult.Experiment_idExperiment==experiment_id) \ .filter(not_(db.ExperimentResult.status.in_(STATUS_PROCESSING))).order_by('idJob').all() return CategoryData().fit([(0, r.instance.name, r.result_code.description, r.resultTime, 0, r.solver_configuration.name, 0) for r in runs]) data = get_data(database, experiment_id, job_count, last_modified_job) if type == 'runs.json': return json_dumps(data.table) elif type == 'solvers.json': return json_dumps(data.solvers) elif type == 'instances.json': return json_dumps(data.instances) elif type == 'membership.json': return json_dumps(data.model._tclass_res_LN.T.tolist()) elif type == 'projection.json': return json_dumps(data.projection_N2.tolist()) else: abort(404)
def encode_exception_report(self, exceptionReport): results = [] data = {} for exception in exceptionReport: data = { "exceptionCode" : str(exception.code), "locator" : exception.locator, "layer" : exception.layer, "ExceptionText" : exception.message, "ExceptionDump" : exception.dump } results.append({"Exception" : data}) return json_dumps({"ExceptionReport" : results})
def encode(self, features, to_string=True, bbox=False, **kwargs): """ Encode a list of features to a JSON object or string. to_string determines whethr it should convert the result to a string or leave it as an object to be encoded later """ results = [] result_data = None minx = miny = 2**31 maxx = maxy = -2**31 for feature in features: fminx, fminy, fmaxx, fmaxy = feature.get_bbox() if fminx < minx: minx = fminx if fminy < miny: miny = fminy if fmaxx > maxx: maxx = fmaxx if fmaxy > maxy: maxy = fmaxy data = self.encode_feature(feature) for key,value in data['properties'].items(): if value and isinstance(value, str): data['properties'][key] = unicode(value,"utf-8") results.append(data) result_data = { 'type':'FeatureCollection', 'features': results, 'crs': self.crs } if bbox: result_data['bbox'] = [minx, miny, maxx, maxy] if to_string: result = json_dumps(result_data) else: result = result_data return result
def borg_explorer_data(database, experiment_id): db = models.get_database(database) or abort(404) experiment = db.session.query( db.Experiment).get(experiment_id) or abort(404) type = request.args.get('type') if type == 'categories.json': return json_dumps([{"path": experiment.name, "name": experiment.name}]) last_modified_job = db.session.query(func.max(db.ExperimentResult.date_modified))\ .filter_by(experiment=experiment).first() job_count = db.session.query( db.ExperimentResult).filter_by(experiment=experiment).count() @synchronized @cache.memoize(7 * 24 * 60 * 60) def get_data(database, experiment_id, job_count, last_modified_job): runs = db.session.query(db.ExperimentResult) \ .filter(db.ExperimentResult.Experiment_idExperiment==experiment_id) \ .filter(not_(db.ExperimentResult.status.in_(STATUS_PROCESSING))).order_by('idJob').all() return CategoryData().fit([ (0, r.instance.name, r.result_code.description, r.resultTime, 0, r.solver_configuration.name, 0) for r in runs ]) data = get_data(database, experiment_id, job_count, last_modified_job) if type == 'runs.json': return json_dumps(data.table) elif type == 'solvers.json': return json_dumps(data.solvers) elif type == 'instances.json': return json_dumps(data.instances) elif type == 'membership.json': return json_dumps(data.model._tclass_res_LN.T.tolist()) elif type == 'projection.json': return json_dumps(data.projection_N2.tolist()) else: abort(404)
def get_experiment_result(database, id): db = models.get_database(database) or abort(404) er = db.session.query(db.ExperimentResult).get(id) or abort(404) return json_dumps(er.to_json())
def result_codes(database): db = models.get_database(database) or abort(404) return json_dumps([rc.to_json() for rc in db.session.query(db.ResultCodes).all()])
def status_codes(database): db = models.get_database(database) or abort(404) return json_dumps( [sc.to_json() for sc in db.session.query(db.StatusCodes).all()])
def result_codes(database): db = models.get_database(database) or abort(404) return json_dumps( [rc.to_json() for rc in db.session.query(db.ResultCodes).all()])
def status_codes(database): db = models.get_database(database) or abort(404) return json_dumps([sc.to_json() for sc in db.session.query(db.StatusCodes).all()])