Best Python code snippet using localstack_python
app.py
Source:app.py
...69 remove_nones = lambda params: {k: v for k, v in params.items() if v is not None}70 timeout = aiohttp.ClientTimeout(total=10)71 async with aiohttp.ClientSession(timeout=timeout) as session:72 async with session.get(73 REQUEST_URL, headers=remove_nones(HEADERS), params=remove_nones(url_params)74 ) as r:75 popup_news_data: Dict[str, Any] = await r.json()76 result: PopupVaccineNews = {"text": "", "buttons": []}77 for record in popup_news_data["records"]:78 if record["fields"]["title"] == "text":79 result["text"] += record["fields"]["words"]80 else:81 result["buttons"].append(record["fields"])82 return result83async def get_hospitals_from_airtable(84 offset: str = "", city: str = "èºåå¸"85) -> List[Hospital]:86 formula: str = f"{{æ½æç«ç¸£å¸ï¼èªåï¼}}='{city}'"87 url_params: AirTableRequestParams = {88 "filterByFormula": formula,89 "offset": offset,90 "maxRecords": 9999,91 "view": "給å端顯示ç¨çè³æ",92 }93 # Must make global constant locally scoped to support typechecking for94 # ternary operators for optionals95 api_key: Optional[str] = AIRTABLE_API_KEY96 REQUEST_URL: str = "https://api.airtable.com/v0/appwPM9XFr1SSNjy4/tblJCPWEMpMg86dI8"97 authorization: Optional[str] = "Bearer " + api_key if api_key is not None else None98 HEADERS: Dict[str, Optional[str]] = {"Authorization": authorization}99 timeout = aiohttp.ClientTimeout(total=10)100 return_list: list[Hospital] = []101 remove_nones = lambda params: {k: v for k, v in params.items() if v is not None}102 async with aiohttp.ClientSession(timeout=timeout) as session:103 async with session.get(104 REQUEST_URL, headers=remove_nones(HEADERS), params=remove_nones(url_params)105 ) as r:106 hospital_json_objects: Dict[str, Any] = await r.json()107 return_list = list(108 map(109 lambda raw_data: parse_airtable_json_for_hospital(110 raw_data["fields"]111 ),112 hospital_json_objects["records"],113 )114 )115 if "offset" in hospital_json_objects:116 return return_list + await get_hospitals_from_airtable(117 hospital_json_objects["offset"]118 )119 else:120 return return_list121async def get_hospitals_links(122 offset: str = "", city: str = "èºåå¸"123) -> List[Dict[str, List[hospitalsLinks]]]:124 formula: str = f"{{縣å¸ï¼ç´æåï¼}}='{city}'"125 url_params: AirTableRequestParams = {126 "filterByFormula": formula,127 "offset": offset,128 "maxRecords": 9999,129 "view": "å端顯示ç¨",130 }131 api_key: Optional[str] = AIRTABLE_API_KEY132 REQUEST_URL: str = "https://api.airtable.com/v0/appwPM9XFr1SSNjy4/%E9%A0%90%E7%B4%84%E9%80%A3%E7%B5%90%E6%B8%85%E5%96%AE"133 authorization: Optional[str] = "Bearer " + api_key if api_key is not None else None134 HEADERS: Dict[str, Optional[str]] = {"Authorization": authorization}135 timeout = aiohttp.ClientTimeout(total=10)136 remove_nones = lambda params: {k: v for k, v in params.items() if v is not None}137 async with aiohttp.ClientSession(timeout=timeout) as session:138 async with session.get(139 REQUEST_URL, headers=remove_nones(HEADERS), params=remove_nones(url_params)140 ) as r:141 links_json_objects: Dict[str, Any] = await r.json()142 recordsWithPrimaryKey = list(143 map(144 lambda record: parse_airtable_json_hospitals_links(145 record["fields"]146 ),147 links_json_objects["records"],148 )149 )150 if "offset" in links_json_objects:151 return recordsWithPrimaryKey + await get_hospitals_links(152 links_json_objects["offset"]153 )...
base.py
Source:base.py
...65 # Graphs66 def create_plots(self, train_recorder, save_dir):67 fig, axes = create_fig((4, 4))68 plot_curves(axes[0, 0],69 xs=[remove_nones(train_recorder.tape['episode_i'])],70 ys=[remove_nones(train_recorder.tape['train_return'])],71 xlabel='episode_i',72 ylabel='train_return')73 axes[0, 1].plot(74 remove_nones(train_recorder.tape['eval_total_steps']),75 remove_nones(train_recorder.tape['eval_return_greedy']),76 label="greedy")77 axes[0, 1].plot(78 remove_nones(train_recorder.tape['eval_total_steps']),79 remove_nones(train_recorder.tape['eval_return_sampled']),80 color='green',81 label="sampled")82 axes[0, 1].set_xlabel('eval_total_steps')83 axes[0, 1].set_ylabel('eval_return')84 axes[0, 1].legend(loc="best")85 plot_curves(axes[0, 2],86 xs=[remove_nones(train_recorder.tape['episode_i'])],87 ys=[remove_nones(train_recorder.tape['episode_len'])],88 xlabel='episode_i',89 ylabel="episode_len")90 plot_curves(axes[1, 0],91 xs=[remove_nones(train_recorder.tape['update_i_actor'])],92 ys=[remove_nones(train_recorder.tape['pi_loss'])],93 xlabel='update_i_actor',94 ylabel='pi_loss')95 axes[1, 1].plot(96 remove_nones(train_recorder.tape['update_i_actor']),97 remove_nones(train_recorder.tape['policy_entropy']),98 label="exact",99 color="orange")100 axes[1, 1].set_xlabel('update_i_actor')101 axes[1, 1].set_ylabel('policy_entropy')102 plot_curves(axes[1, 2],103 xs=[remove_nones(train_recorder.tape['update_i_actor'])],104 ys=[remove_nones(train_recorder.tape['total_policy_loss'])],105 xlabel='update_i_actor',106 ylabel="total_policy_loss")107 # extra plots axes[2:,:] to be defined by child class...
vae_model.py
Source:vae_model.py
...69 # Graphs70 def create_plots(self, train_recorder, save_dir):71 fig, axes = create_fig((3, 3))72 plot_curves(axes[0, 0],73 xs=[remove_nones(train_recorder.tape['update_i'])],74 ys=[remove_nones(train_recorder.tape['reconstruction_loss'])],75 xlabel='update_i',76 ylabel='reconstruction_loss')77 plot_curves(axes[0, 1],78 xs=[remove_nones(train_recorder.tape['update_i'])],79 ys=[remove_nones(train_recorder.tape['prior_loss'])],80 xlabel='update_i',81 ylabel='prior_loss')82 plot_curves(axes[0, 2],83 xs=[remove_nones(train_recorder.tape['update_i'])],84 ys=[remove_nones(train_recorder.tape['total_loss'])],85 xlabel='update_i',86 ylabel='total_loss')87 plot_curves(axes[1, 0],88 xs=[remove_nones(train_recorder.tape['update_i'])],89 ys=[remove_nones(train_recorder.tape['lr'])],90 xlabel='update_i',91 ylabel='lr')92 plt.tight_layout()93 fig.savefig(str(save_dir / 'graphs.png'))...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!