How to use _pipeline method in hypothesis

Best Python code snippet using hypothesis

lstm.py

Source:lstm.py Github

copy

Full Screen

1import unittest2import numpy as np3from sentivi import Pipeline4from sentivi.data import TextEncoder, DataLoader5from sentivi.text_processor import TextProcessor6from sentivi.classifier import LSTMClassifier7class LSTMTestCase(unittest.TestCase):8 INPUT_FILE = './data/dev.vi'9 OUTPUT_FILE = './data/dev_test.vi'10 SAVED_PATH = './weights/pipeline_test.sentivi'11 W2V_PRETRAINED = './pretrained/wiki.vi.model.bin.gz'12 class EncodingAliases:13 ONE_HOT = 'one-hot'14 BOW = 'bow'15 TF_IDF = 'tf-idf'16 W2V = 'word2vec'17 TRANSFORMER = 'transformer'18 text_processor = TextProcessor(methods=['remove_punctuation', 'word_segmentation'])19 def test_text_processor(self):20 self.assertIsInstance(self.text_processor, TextProcessor)21 self.assertEqual(self.text_processor('Trường đại học, Tôn Đức Thắng, Hồ; Chí Minh.'),22 'Trường đại_học Tôn_Đức_Thắng Hồ_Chí_Minh')23 def test_one_hot_tt(self):24 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),25 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.ONE_HOT),26 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=True))27 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)28 pipeline.save(LSTMTestCase.SAVED_PATH)29 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)30 self.assertIsInstance(_pipeline, Pipeline)31 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '32 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',33 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '34 'chuẩn, đẹppppp'])35 self.assertIsInstance(predict_results, np.ndarray)36 def test_one_hot_tf(self):37 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),38 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.ONE_HOT),39 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=False))40 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)41 pipeline.save(LSTMTestCase.SAVED_PATH)42 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)43 self.assertIsInstance(_pipeline, Pipeline)44 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '45 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',46 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '47 'chuẩn, đẹppppp'])48 self.assertIsInstance(predict_results, np.ndarray)49 def test_one_hot_ft(self):50 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),51 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.ONE_HOT),52 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=True))53 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)54 pipeline.save(LSTMTestCase.SAVED_PATH)55 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)56 self.assertIsInstance(_pipeline, Pipeline)57 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '58 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',59 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '60 'chuẩn, đẹppppp'])61 self.assertIsInstance(predict_results, np.ndarray)62 def test_one_hot_ff(self):63 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),64 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.ONE_HOT),65 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=False))66 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)67 pipeline.save(LSTMTestCase.SAVED_PATH)68 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)69 self.assertIsInstance(_pipeline, Pipeline)70 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '71 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',72 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '73 'chuẩn, đẹppppp'])74 self.assertIsInstance(predict_results, np.ndarray)75 def test_bow_tt(self):76 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),77 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.BOW),78 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=True))79 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)80 pipeline.save(LSTMTestCase.SAVED_PATH)81 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)82 self.assertIsInstance(_pipeline, Pipeline)83 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '84 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',85 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '86 'chuẩn, đẹppppp'])87 self.assertIsInstance(predict_results, np.ndarray)88 def test_bow_tf(self):89 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),90 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.BOW),91 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=False))92 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)93 pipeline.save(LSTMTestCase.SAVED_PATH)94 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)95 self.assertIsInstance(_pipeline, Pipeline)96 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '97 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',98 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '99 'chuẩn, đẹppppp'])100 self.assertIsInstance(predict_results, np.ndarray)101 def test_bow_ff(self):102 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),103 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.BOW),104 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=False))105 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)106 pipeline.save(LSTMTestCase.SAVED_PATH)107 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)108 self.assertIsInstance(_pipeline, Pipeline)109 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '110 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',111 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '112 'chuẩn, đẹppppp'])113 self.assertIsInstance(predict_results, np.ndarray)114 def test_bow_ft(self):115 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=1),116 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.BOW),117 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=True))118 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)119 pipeline.save(LSTMTestCase.SAVED_PATH)120 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)121 self.assertIsInstance(_pipeline, Pipeline)122 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '123 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',124 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '125 'chuẩn, đẹppppp'])126 self.assertIsInstance(predict_results, np.ndarray)127 def test_tf_idf_tt(self):128 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),129 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.TF_IDF),130 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=True))131 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)132 pipeline.save(LSTMTestCase.SAVED_PATH)133 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)134 self.assertIsInstance(_pipeline, Pipeline)135 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '136 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',137 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '138 'chuẩn, đẹppppp'])139 self.assertIsInstance(predict_results, np.ndarray)140 def test_tf_idf_tf(self):141 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),142 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.TF_IDF),143 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=False))144 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)145 pipeline.save(LSTMTestCase.SAVED_PATH)146 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)147 self.assertIsInstance(_pipeline, Pipeline)148 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '149 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',150 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '151 'chuẩn, đẹppppp'])152 self.assertIsInstance(predict_results, np.ndarray)153 def test_tf_idf_ft(self):154 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),155 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.TF_IDF),156 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=True))157 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)158 pipeline.save(LSTMTestCase.SAVED_PATH)159 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)160 self.assertIsInstance(_pipeline, Pipeline)161 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '162 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',163 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '164 'chuẩn, đẹppppp'])165 self.assertIsInstance(predict_results, np.ndarray)166 def test_tf_idf_ff(self):167 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),168 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.TF_IDF),169 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=False))170 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)171 pipeline.save(LSTMTestCase.SAVED_PATH)172 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)173 self.assertIsInstance(_pipeline, Pipeline)174 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '175 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',176 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '177 'chuẩn, đẹppppp'])178 self.assertIsInstance(predict_results, np.ndarray)179 def test_word2vec_tt(self):180 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),181 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.W2V,182 model_path=LSTMTestCase.W2V_PRETRAINED),183 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=True))184 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)185 pipeline.save(LSTMTestCase.SAVED_PATH)186 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)187 self.assertIsInstance(_pipeline, Pipeline)188 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '189 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',190 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '191 'chuẩn, đẹppppp'])192 self.assertIsInstance(predict_results, np.ndarray)193 def test_word2vec_tf(self):194 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),195 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.W2V,196 model_path=LSTMTestCase.W2V_PRETRAINED),197 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=True, attention=False))198 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)199 pipeline.save(LSTMTestCase.SAVED_PATH)200 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)201 self.assertIsInstance(_pipeline, Pipeline)202 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '203 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',204 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '205 'chuẩn, đẹppppp'])206 self.assertIsInstance(predict_results, np.ndarray)207 def test_word2vec_ff(self):208 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),209 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.W2V,210 model_path=LSTMTestCase.W2V_PRETRAINED),211 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=False))212 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)213 pipeline.save(LSTMTestCase.SAVED_PATH)214 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)215 self.assertIsInstance(_pipeline, Pipeline)216 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '217 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',218 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '219 'chuẩn, đẹppppp'])220 self.assertIsInstance(predict_results, np.ndarray)221 def test_word2vec_ft(self):222 pipeline = Pipeline(DataLoader(text_processor=self.text_processor, n_grams=3),223 TextEncoder(encode_type=LSTMTestCase.EncodingAliases.W2V,224 model_path=LSTMTestCase.W2V_PRETRAINED),225 LSTMClassifier(num_labels=3, num_epochs=3, bidirectional=False, attention=True))226 pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)227 pipeline.save(LSTMTestCase.SAVED_PATH)228 _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)229 self.assertIsInstance(_pipeline, Pipeline)230 predict_results = _pipeline.predict(['hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '231 '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',232 'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '233 'chuẩn, đẹppppp'])...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1from flask import Flask, render_template, redirect, jsonify2from flask_pymongo import PyMongo3from pymongo import MongoClient4from flask import request5import json6import pandas as pd7from flask import jsonify8# Create an instance of Flask9app = Flask(__name__)10# Use PyMongo to establish Mongo connection11# mongo = PyMongo(app, uri="mongodb://localhost:27017/Project")12connectionString = "mongodb://dbAdmin:Vol8e3v5XLGYrwTK@cluster0-shard-00-00-0dend.mongodb.net:27017,cluster0-shard-00-01-0dend.mongodb.net:27017,cluster0-shard-00-02-0dend.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true"13dbClient = MongoClient(connectionString)14db = dbClient["cdmx_pollution"]15# Route to render index.html template using data from Mongo16####### Página HTML17@app.route("/")18def home():19 return render_template("index.html")20@app.route("/overview")21def overview():22 return render_template("overview.html")23@app.route("/visualizations")24def plots():25 return render_template("visualizations.html")26@app.route("/data")27def datah():28 return render_template("data.html")29@app.route("/heatmaps")30def heatmaps():31 return render_template("heatmap.html")32@app.route("/townhalls")33def townhalls():34 return render_template("townhalls.html")35@app.route("/stations")36def stations():37 return render_template("stations.html")38@app.route("/team")39def team():40 return render_template("team.html")41####### Termina HTML42###### Empieza Mapa Interactivo43@app.route("/heatmap.html")44def heatmap():45 return render_template("heatmap.html")46@app.route("/contaminants/")47def data1():48 _args = verifyQueryParameters(request.args)49 docs = getContaminants(**_args)50 df = pd.DataFrame(list(docs))51 print(df.head(5))52 result = {53 'data': json.loads(df.to_json(orient='records'))54 # 'data': {}55 }56 return jsonify(result)57def getContaminants(match, project = {}, skip = 0, limit = 1000, orient='records'):58 _pipeline = [59 {60 '$match': {61 **match62 }63 },64 {65 '$project': {66 '_id': 067 }68 }, 69 {70 '$sort': {71 'date': 172 }73 }, 74 {75 '$skip': skip76 }, 77 {78 '$limit': limit79 } 80 ]81 print(_pipeline)82 if len(project) > 0:83 _pipeline.append({'$project': { **project }})84 docs = db.contaminants2016.aggregate(_pipeline)85 # for doc in docs:86 # print(doc)87 return docs88# -----------------89@app.route("/emergencies/")90def data2():91 _args = verifyQueryParameters(request.args)92 docs = getEmergencies(**_args)93 df = pd.DataFrame(list(docs))94 print(df.head(5))95 result = {96 'data': json.loads(df.to_json(orient='records'))97 # 'data': {}98 }99 return jsonify(result)100def getEmergencies(match, project = {}, skip = 0, limit = 1000, orient='records'):101 _pipeline = [102 {103 '$match': {104 **match105 }106 },107 {108 '$project': {109 '_id': 0110 }111 }, 112 {113 '$sort': {114 'date': 1115 }116 }, 117 {118 '$skip': skip119 }, 120 {121 '$limit': limit122 } 123 ]124 print(_pipeline)125 if len(project) > 0:126 _pipeline.append({'$project': { **project }})127 docs = db.respiratorias2016.aggregate(_pipeline)128 # for doc in docs:129 # print(doc)130 return docs131# -----------------132# -----------------133@app.route("/municipality/")134def data3():135 _args = verifyQueryParameters(request.args)136 docs = getMunicipality(**_args)137 df = pd.DataFrame(list(docs))138 print(df.head(5))139 result = {140 'data': json.loads(df.to_json(orient='records'))141 # 'data': {}142 }143 return jsonify(result)144def getMunicipality(match, project = {}, skip = 0, limit = 1000, orient='records'):145 _pipeline = [146 {147 '$match': {148 **match149 }150 },151 {152 '$project': {153 '_id': 0154 }155 }, 156 {157 '$sort': {158 'date': 1159 }160 }, 161 {162 '$skip': skip163 }, 164 {165 '$limit': limit166 } 167 ]168 print(_pipeline)169 if len(project) > 0:170 _pipeline.append({'$project': { **project }})171 docs = db.daily_pollutants.aggregate(_pipeline)172 # for doc in docs:173 # print(doc)174 return docs175# ------------------------176# -----------------177@app.route("/municipality_and_emergencies/")178def data4():179 _args = verifyQueryParameters(request.args)180 docs = getMunAndEmer(**_args)181 df = pd.DataFrame(list(docs))182 print(df.head(5))183 result = {184 'data': json.loads(df.to_json(orient='records'))185 # 'data': {}186 }187 return jsonify(result)188def getMunAndEmer(match, project = {}, skip = 0, limit = 1000, orient='records'):189 _pipeline = [190 {191 '$match': {192 **match193 }194 },195 {196 '$project': {197 '_id': 0198 }199 }, 200 {201 '$sort': {202 'date': 1203 }204 }, 205 {206 '$skip': skip207 }, 208 {209 '$limit': limit210 } 211 ]212 print(_pipeline)213 if len(project) > 0:214 _pipeline.append({'$project': { **project }})215 docs = db.all_data.aggregate(_pipeline)216 # for doc in docs:217 # print(doc)218 return docs219# ------------------------220def verifyQueryParameters(args):221 _args = { }222 parametersAllowed = [223 'q',224 'project',225 'skip',226 'limit',227 'orient'228 ]229 if args.get('q'):230 qDict = json.loads(args.get('q'))231 if len(qDict) == 0:232 raise Exception("q parameter can't be empty")233 _args['match'] = qDict234 235 if args.get('project'):236 _args['project'] = json.loads(args.get('project'))237 238 if args.get('skip'):239 _args['skip'] = json.loads(args.get('skip'))240 if args.get('limit'):241 _args['limit'] = json.loads(args.get('limit'))242 if args.get('orient'):243 _args['orient'] = json.loads(args.get('orient'))244 else:245 _args['orient'] = 'records'246 return _args247######Termina Mapa Interactivo248@app.route("/diseases/")249def diseases():250 _args = verifyQueryParameters(request.args)251 docs = getDiseases(**_args)252 df = pd.DataFrame(list(docs))253 print(df.head(5))254 jsindex=list(df['index'])255 jscases=list(df['CASES'])256 jsO3=list(df['O3'])257 jsO3m=list(df['O3m'])258 jsPM10=list(df['PM10'])259 jsPM10m=list(df['PM10m'])260 trace = {261 "date":jsindex,262 "cases":jscases,263 "O3":jsO3,264 "PM10":jsPM10,265 "O3m":jsO3m,266 "PM10m":jsPM10m267 }268 return jsonify(trace)269def getDiseases(match, project = {}, skip = 0, limit = 366, orient='records'):270 _pipeline = [271 {272 '$match': {273 **match274 }275 },276 {277 '$project': {278 '_id': 0279 }280 }, 281 {282 '$sort': {283 'date': 1284 }285 }, 286 {287 '$skip': skip288 }, 289 {290 '$limit': limit291 } 292 ]293 print(_pipeline)294 if len(project) > 0:295 _pipeline.append({'$project': { **project }})296 docs = db.poll_vs_dis.aggregate(_pipeline)297 # for doc in docs:298 # print(doc)299 return docs300###### Termina Pollutans Levels Town-HallTown and Stations301 302if __name__ == "__main__":...

Full Screen

Full Screen

gstpipeline.py

Source:gstpipeline.py Github

copy

Full Screen

1import logging2import gi3from gi.repository import Gst4gi.require_version('Gst', '1.0')5class GstPipeline(object):6 """7 Base class to initialize any Gstreamer Pipeline from string8 """9 10 def __init__(self, command):11 """12 :param command: gstreamer plugins string13 :type command: str14 :param fps_interval: raise FPS event every N seconds15 :type fps_interval: float (in seconds)16 """17 if not isinstance(command, str):18 raise ValueError("Invalid type. {} != {}".format(type(command), 19 "str"))20 21 super(GstPipeline, self).__init__()22 self._pipeline = None23 self._active = False24 logging.info('%s %s', 'gst-launch-1.0', command)25 """26 Gsteamer Pipeline27 https://gstreamer.freedesktop.org/documentation/application-development/introduction/basics.html28 """29 self._pipeline = Gst.parse_launch(command)30 if not isinstance(self._pipeline, Gst.Pipeline):31 raise ValueError("Invalid type. {} != {}".format(type(self._pipeline), 32 "Gst.Pipeline"))33 """34 Gsteamer Message Bus35 https://gstreamer.freedesktop.org/documentation/application-development/basics/bus.html36 """37 self._bus = self._pipeline.get_bus() 38 self._bus.add_signal_watch()39 self._bus.connect("message", self._bus_call, None)40 41 @staticmethod42 def create_element(self, name):43 """44 Creates Gstreamer element45 :param name: https://gstreamer.freedesktop.org/documentation/plugins.html46 :type name: str47 :rtype: Gst.Element48 """ 49 return Gst.ElementFactory.make(name)50 def get_element(self, name):51 """52 Get Gst.Element from pipeline by name53 :param name:54 :type name: str55 :rtype: Gst.Element56 """ 57 element = self._pipeline.get_by_name(name)58 return element is not None, element 59 def start(self): 60 # https://lazka.github.io/pgi-docs/Gst-1.0/enums.html#Gst.StateChangeReturn61 self._pipeline.set_state(Gst.State.PLAYING)62 def stop(self):63 # https://lazka.github.io/pgi-docs/Gst-1.0/enums.html#Gst.StateChangeReturn64 self._pipeline.set_state(Gst.State.NULL)65 def bus(self):66 return self._bus 67 68 def pipeline(self):69 return self._pipeline70 71 def _bus_call(self, bus, message, loop):72 mtype = message.type73 """74 Gstreamer Message Types and how to parse75 https://lazka.github.io/pgi-docs/Gst-1.0/flags.html#Gst.MessageType76 """77 if mtype == Gst.MessageType.EOS:78 self.stop()79 80 elif mtype == Gst.MessageType.ERROR:81 err, debug = message.parse_error()82 logging.error("{0}: {1}".format(err, debug)) 83 self.stop() 84 elif mtype == Gst.MessageType.WARNING:85 err, debug = message.parse_warning()86 logging.warning("{0}: {1}".format(err, debug)) 87 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful