def sim3_decoder(o: dict): """ Decodes the given JSON string and returns its respective model. This function should be passed into the 'object_hook' parameter in json.load(). :param o: JSON string as a dict. :return: the respective model object. """ from providentia.repository import tbl_benchmark sim = Sim3() sim.id = o['id'] sim.benchmark = tbl_benchmark.find(o['benchmark_id']) sim.no_responses = o['no_responses'] return sim
def city_sentiment_decoder(o: dict): """ Decodes the given JSON string and returns its respective model. This function should be passed into the 'object_hook' parameter in json.load(). :param o: JSON string as a dict. :return: the respective model object. """ from providentia.repository import tbl_benchmark city_sentiment = CitySentimentResult() city_sentiment.id = o['id'] city_sentiment.benchmark = tbl_benchmark.find(o['benchmark_id']) city_sentiment.stars = o['stars'] city_sentiment.sentiment = o['sentiment'] return city_sentiment
def result_find(benchmark_id): """Get a specific benchmark.""" try: benchmark = tbl_benchmark.find(benchmark_id) except Exception as e: logging.error(str(e)) return Response({"Unexpected error while querying database!"}, status=500) if benchmark is None: return Response({"Benchmark not found!"}, status=404) return Response(json.dumps(benchmark, default=model_encoder), status=200, mimetype='application/json')
def kate_decoder(o: dict): """ Decodes the given JSON string and returns its respective model. This function should be passed into the 'object_hook' parameter in json.load(). :param o: JSON string as a dict. :return: the respective model object. """ from providentia.repository import tbl_benchmark kate = KateResult() kate.id = o['id'] kate.business = o['business'] kate.benchmark = tbl_benchmark.find(o['benchmark_id']) kate.sentiment_average = o['sentiment_average'] kate.star_average = o['star_average'] kate.total_reviews = o['total_reviews'] return kate
def review_trend_decoder(o: dict): """ Decodes the given JSON string and returns its respective model. This function should be passed into the 'object_hook' parameter in json.load(). :param o: JSON string as a dict. :return: the respective model object. """ from providentia.repository import tbl_benchmark review_trend = ReviewTrendResult() review_trend.id = o['id'] review_trend.benchmark = tbl_benchmark.find(o['benchmark_id']) review_trend.stars = o['stars'] review_trend.length = o['length'] review_trend.cool = o['cool'] review_trend.funny = o['funny'] review_trend.useful = o['useful'] review_trend.sentiment = o['sentiment'] return review_trend