Best Python code snippet using uiautomator
reshape_data.py
Source:reshape_data.py  
1import csv2outFile = csv.writer(open("data/HAI_all_years.csv", "wb"))3years = ["2013", "2006", "2000"]4data = {}5for year in years:6	if year == "2000":7		cr = csv.reader(open("data/source/HAI_COMMS_2000_Final_Map_Output.csv", "rU"))8		head = cr.next()9		i = 010		indices = {}11		for h in head:12			indices[h] = i13			i+= 114		for row in cr:15			fips = row[indices["county"]]16			if fips not in data:17				data[fips] = {"name":"", "2000":{"scalar":"","hud":"","maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2006":{"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2013": {"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}}18			flag = row[indices["state_flag"]]19			if flag == "0":20				data[fips][year]["flag"] = flag21			else:22				data[fips][year]["flag"] = "1"23			data[fips]["FIPS"] = fips24			if flag == "0":25				p100 = float(row[indices["per100"]])26				if p100 > 100:27					data[fips][year]["scalar"] = 100.0 / p10028				else:29					data[fips][year]["scalar"] = 130				data[fips][year]["usdaOn_hudOn"] = p10031				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["hudper100"]])32				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["USDAper100"]])33				data[fips][year]["usdaOff_hudOff"] = float(row[indices["per100_no_assisted"]])34				data[fips][year]["totalPop"] = row[indices["Total"]]35				data[fips][year]["usdaOn_hudOnNum"] = row[indices["units"]]36				data[fips][year]["usdaOn_hudOffNum"] = row[indices["Units_No_HUD"]]37				data[fips][year]["usdaOff_hudOnNum"] = row[indices["Units_no_usda"]]38				data[fips][year]["usdaOff_hudOffNum"] = row[indices["Unitsnoasst"]]39				data[fips][year]["hud"] = 040				data[fips][year]["usda"] = 041				data[fips][year]["maxELI"] = row[indices["l30_4"]]42				data[fips][year]["minELI"] = row[indices["l30_4"]]43				data[fips][year]["ami"] = row[indices["l30_4"]]44			elif row[indices["ST_Units"]] != "":45				p100 = float(row[indices["ST_per100"]])46				if p100 > 100:47					data[fips][year]["scalar"] = 100.0 / p10048				else:49					data[fips][year]["scalar"] = 150				data[fips][year]["usdaOn_hudOn"] = p10051				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["ST_Hudper100"]])52				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["ST_USDAper100"]])53				data[fips][year]["usdaOff_hudOff"] = float(row[indices["ST_per100_No_Assisted"]])54				data[fips][year]["totalPop"] = row[indices["ST_Total"]]55				data[fips][year]["usdaOn_hudOnNum"] = row[indices["ST_Units"]]56				data[fips][year]["usdaOn_hudOffNum"] = row[indices["ST_Units_No_HUD"]]57				data[fips][year]["usdaOff_hudOnNum"] = row[indices["ST_Units_no_USDA"]]58				data[fips][year]["usdaOff_hudOffNum"] = row[indices["ST_Unitsnoasst"]]59				data[fips][year]["hud"] = 060				data[fips][year]["usda"] = 061				data[fips][year]["maxELI"] = row[indices["MaxEli"]]62				data[fips][year]["minELI"] = row[indices["MinEli"]]63	elif year == "2006":64		cr = csv.reader(open("data/source/HAI_COMMS_2007_Final_Map_Output.csv", "rU"))65		head = cr.next()66		i = 067		indices = {}68		for h in head:69			indices[h] = i70			i+= 171		for row in cr:72			fips = row[indices["county"]]73			if fips not in data:74				data[fips] = {"name":"", "2000":{"scalar":"","hud":"","maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2006":{"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2013": {"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}}75			# if year == "2013":76			# 	ignore = row[indices["Unweighted ELI obs < 10"]]77			# 	state = row[indices["State Name"]]78			# 	name = row[indices["County Name"]]79			# 	data[fips]["state"] = state80			# 	data[fips]["name"] = name81			flag = row[indices["state_flag"]]82			if flag == "0":83				data[fips][year]["flag"] = flag84			else:85				data[fips][year]["flag"] = "1"86			data[fips]["FIPS"] = fips87			if flag == "0":88				p100 = float(row[indices["per100"]])89				if p100 > 100:90					data[fips][year]["scalar"] = 100.0 / p10091				else:92					data[fips][year]["scalar"] = 193				data[fips][year]["usdaOn_hudOn"] = p10094				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["hudper100"]])95				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["USDAper100"]])96				data[fips][year]["usdaOff_hudOff"] = float(row[indices["per100_no_assisted"]])97				data[fips][year]["totalPop"] = row[indices["Total"]]98				data[fips][year]["usdaOn_hudOnNum"] = row[indices["units"]]99				data[fips][year]["usdaOn_hudOffNum"] = row[indices["Units_No_HUD"]]100				data[fips][year]["usdaOff_hudOnNum"] = row[indices["Units_no_usda"]]101				data[fips][year]["usdaOff_hudOffNum"] = row[indices["Unitsnoasst"]]102				data[fips][year]["hud"] = 0103				data[fips][year]["usda"] = 0104				data[fips][year]["maxELI"] = row[indices["l30_4"]]105				data[fips][year]["minELI"] = row[indices["l30_4"]]106				data[fips][year]["ami"] = row[indices["l30_4"]]107			elif row[indices["ST_Units"]] != "":108				p100 = float(row[indices["ST_per100"]])109				if p100 > 100:110					data[fips][year]["scalar"] = 100.0 / p100111				else:112					data[fips][year]["scalar"] = 1113				data[fips][year]["usdaOn_hudOn"] = p100114				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["ST_Hudper100"]])115				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["ST_USDAper100"]])116				data[fips][year]["usdaOff_hudOff"] = float(row[indices["ST_per100_No_Assisted"]])117				data[fips][year]["totalPop"] = row[indices["ST_Total"]]118				data[fips][year]["usdaOn_hudOnNum"] = row[indices["ST_Units"]]119				data[fips][year]["usdaOn_hudOffNum"] = row[indices["ST_Units_No_HUD"]]120				data[fips][year]["usdaOff_hudOnNum"] = row[indices["ST_Units_no_USDA"]]121				data[fips][year]["usdaOff_hudOffNum"] = row[indices["ST_Unitsnoasst"]]122				data[fips][year]["hud"] = 0123				data[fips][year]["usda"] = 0124				data[fips][year]["maxELI"] = row[indices["MaxEli"]]125				data[fips][year]["minELI"] = row[indices["MinEli"]]126			127	elif year == "2013":128		cr = csv.reader(open("data/source/HAI_COMMS_2012_Final_Map_Output.csv", "rU"))129		head = cr.next()130		i = 0131		indices = {}132		for h in head:133			indices[h] = i134			i+= 1135		print indices136		for row in cr:137			fips = row[indices["county"]]138			if fips not in data:139				data[fips] = {"name":"", "2000":{"scalar":"","hud":"","maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2006":{"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}, "2013": {"scalar":"","usda":"", "hud":"", "maxELI":"", "minELI":"", "ami":"","usdaOn_hudOn":"","usdaOn_hudOff":"","usdaOff_hudOn":"","usdaOff_hudOff":"","totalPop":"","usdaOn_hudOnNum":"","usdaOn_hudOffNum":"","usdaOff_hudOnNum":"", "usdaOff_hudOffNum":"","flag":""}}140			# ignore = 0141			# state = row[indices["State Name"]]142			name = row[indices["countyname"]]143			data[fips]["name"] = name144			flag = row[indices["state_flag"]]145			if flag == "0":146				data[fips][year]["flag"] = flag147			else:148				data[fips][year]["flag"] = "1"149			data[fips]["FIPS"] = fips150			if flag == "0":151				p100 = float(row[indices["per100"]])152				if p100 > 100:153					data[fips][year]["scalar"] = 100.0 / p100154				else:155					data[fips][year]["scalar"] = 1156				data[fips][year]["usdaOn_hudOn"] = p100157				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["hudper100"]])158				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["USDAper100"]])159				data[fips][year]["usdaOff_hudOff"] = float(row[indices["per100_no_assisted"]])160				data[fips][year]["totalPop"] = row[indices["Total"]]161				data[fips][year]["usdaOn_hudOnNum"] = row[indices["units"]]162				data[fips][year]["usdaOn_hudOffNum"] = row[indices["Units_No_HUD"]]163				data[fips][year]["usdaOff_hudOnNum"] = row[indices["Units_no_usda"]]164				data[fips][year]["usdaOff_hudOffNum"] = row[indices["Unitsnoasst"]]165				data[fips][year]["hud"] = 0166				data[fips][year]["usda"] = 0167				data[fips][year]["maxELI"] = row[indices["l30_4"]]168				data[fips][year]["minELI"] = row[indices["l30_4"]]169				data[fips][year]["ami"] = row[indices["l30_4"]]170			elif row[indices["ST_Units"]] != "":171				p100 = float(row[indices["ST_per100"]])172				if p100 > 100:173					data[fips][year]["scalar"] = 100.0 / p100174				else:175					data[fips][year]["scalar"] = 1176				data[fips][year]["usdaOn_hudOn"] = p100177				data[fips][year]["usdaOn_hudOff"] = p100 - float(row[indices["ST_Hudper100"]])178				data[fips][year]["usdaOff_hudOn"] = p100 - float(row[indices["ST_USDAper100"]])179				data[fips][year]["usdaOff_hudOff"] = float(row[indices["ST_per100_No_Assisted"]])180				data[fips][year]["totalPop"] = row[indices["ST_Total"]]181				data[fips][year]["usdaOn_hudOnNum"] = row[indices["ST_Units"]]182				data[fips][year]["usdaOn_hudOffNum"] = row[indices["ST_Units_No_HUD"]]183				data[fips][year]["usdaOff_hudOnNum"] = row[indices["ST_Units_no_USDA"]]184				data[fips][year]["usdaOff_hudOffNum"] = row[indices["ST_Unitsnoasst"]]185				data[fips][year]["hud"] = 0186				data[fips][year]["usda"] = 0187				data[fips][year]["maxELI"] = row[indices["MaxEli"]]188				data[fips][year]["minELI"] = row[indices["MinEli"]]189		190outFile.writerow(["FIPS", "flagged", "name", "ami2000","ami2006","ami2013", "usdaOnhudOn2000","usdaOnhudOff2000","usdaOffhudOn2000","usdaOffhudOff2000","totalPop2000", "usdaOnhudOnNum2000","usdaOnhudOffNum2000","usdaOffhudOnNum2000","usdaOffhudOffNum2000", "usdaOnhudOn2006","usdaOnhudOff2006","usdaOffhudOn2006","usdaOffhudOff2006","totalPop2006", "usdaOnhudOnNum2006","usdaOnhudOffNum2006","usdaOffhudOnNum2006","usdaOffhudOffNum2006", "usdaOnhudOn2013","usdaOnhudOff2013","usdaOffhudOn2013","usdaOffhudOff2013","totalPop2013", "usdaOnhudOnNum2013","usdaOnhudOffNum2013","usdaOffhudOnNum2013","usdaOffhudOffNum2013","maxELI2000","minELI2000","maxELI2006","minELI2006","maxELI2013","minELI2013","hud2000","hud2006","hud2013","usda2006","usda2013","scalar2000","scalar2006","scalar2013"])191for fips in data:192	d = data[fips]...off-canvas.es6.js
Source:off-canvas.es6.js  
...55     * @param {jQuery} $element56     *   The target element.57     */58    removeOffCanvasEvents($element) {59      $element.off('.off-canvas');60      $(document).off('.off-canvas');61      $(window).off('.off-canvas');62    },63    /**64     * Handler fired before an off-canvas dialog has been opened.65     *66     * @param {Object} settings67     *   Settings related to the composition of the dialog.68     *69     * @return {undefined}70     */71    beforeCreate({ settings, $element }) {72      // Clean up previous dialog event handlers.73      Drupal.offCanvas.removeOffCanvasEvents($element);74      $('body').addClass('js-off-canvas-dialog-open');75      // @see http://api.jqueryui.com/position/...off-canvas.js
Source:off-canvas.js  
...13    isOffCanvas: function isOffCanvas($element) {14      return $element.is('#drupal-off-canvas');15    },16    removeOffCanvasEvents: function removeOffCanvasEvents($element) {17      $element.off('.off-canvas');18      $(document).off('.off-canvas');19      $(window).off('.off-canvas');20    },21    beforeCreate: function beforeCreate(_ref) {22      var settings = _ref.settings,23          $element = _ref.$element;24      Drupal.offCanvas.removeOffCanvasEvents($element);25      $('body').addClass('js-off-canvas-dialog-open');26      settings.position = {27        my: 'left top',28        at: Drupal.offCanvas.getEdge() + ' top',29        of: window30      };31      var position = settings.drupalOffCanvasPosition;32      var height = position === 'side' ? $(window).height() : settings.height;33      var width = position === 'side' ? settings.width : '100%';...test_off.py
Source:test_off.py  
1@app.route('/editOffDay', methods=['GET', 'POST'])2def off_day():3    global clinic_id4    create_user_form = OffDay(request.form)5    if request.method == 'POST':6        off_day_dict= {}7        od_db = shelve.open('clinic_od_storage.db', 'c')8        try:9            off_day_dict = od_db[clinic_id]10        except:11            print("Error in retrieving Users from storage.db.")12        clinic_od = Clinic.OffDay(create_user_form.start.data, create_user_form.end.data, create_user_form.reason.data)13        off_day_dict[clinic_od.get_id()] = clinic_od14        od_db[clinic_id] = off_day_dict15        print(clinic_id, "was stored in storage.db successfully with Clinic ID =", clinic_od.get_start())16        od_db.close()17        return redirect(url_for('retrieve_off_day'))18    return render_template('createOffDay.html', form=create_user_form)19@app.route('/retrieveOffDay')20def retrieve_off_day():21    global clinic_id22    off_day_dict = {}23    try:24        od_db = shelve.open('clinic_od_storage.db', 'r')25        off_day_dict = od_db[clinic_id] #have the dict of the operating hours26        od_db.close()27    except:28        od_db = {}29    # off_day_dict = od_db[clinic_id] #have the dict of the operating hours30    return render_template('retrieveOffDay.html', off_day_dict=off_day_dict)31@app.route('/updateOffDay/<int:id>/', methods=['GET', 'POST'])32def update_off_day(id):33    update_user_form = OffDay(request.form)34    global clinic_id35    if request.method == 'POST':36        od_db = shelve.open('clinic_od_storage.db', 'w')37        off_day_dict = od_db[clinic_id]38        off_day = off_day_dict[id]39        off_day.set_start(update_user_form.start.data)40        off_day.set_end(update_user_form.end.data)41        off_day.set_reason(update_user_form.reason.data)42        # clinic_od = Clinic.OffDay(update_user_form.start.data, update_user_form.end.data, update_user_form.reason.data)43        # period = [clinic_od.get_start(), clinic_od.get_end(), clinic_od.get_reason()]44        # off_day_dict[clinic_od.get_start()] = period45        od_db[clinic_id] = off_day_dict46        od_db.close()47        return redirect(url_for('retrieve_off_day'))48    else:49        off_day_dict = {}50        od_db = shelve.open('clinic_od_storage.db', 'w')51        off_day_dict = od_db[clinic_id] #have the dict of the operating hours52        od_db.close()53        off_day = off_day_dict[id]54        update_user_form.start.data = off_day.get_start()55        update_user_form.end.data = off_day.get_end()56        update_user_form.reason.data = off_day.get_reason()57        return render_template('updateOffDay.html', form=update_user_form)58@app.route('/deleteOffDay/<int:id>/', methods=['POST', 'GET'])59def delete_off_day(id):60    global clinic_id61    off_day_dict = {}62    try:63        od_db = shelve.open('clinic_od_storage.db', 'w')64        off_day_dict = od_db[clinic_id]65    except:66        print("Error in retrieving Users from storage.db.")67    print('hi this is start =',id)68    if id in off_day_dict:69        off_day_dict.pop(id)70    for i in off_day_dict:71        print(i)72    od_db[clinic_id] = off_day_dict73    od_db.close()74class OffDay:75    count_id = 076    def __init__(self, start, end, reason):77        OffDay.count_id +=178        self.__id = OffDay.count_id79        self.__start = start80        self.__end = end81        self.__reason = reason82    def set_id(self, id):83        self.__id = id84    def get_id(self):85        return self.__id86    def set_start(self, start):87        self.__start = start88    def get_start(self):89        return self.__start90    def set_end(self, end):91        self.__end = end92    def get_end(self):93        return self.__end94    def set_reason(self, reason):95        self.__reason = reason96    def get_reason(self):97        return self.__reason98{% extends "base.html" %}99{% block title %}Library Loan System - Retrieve Users{% endblock %}100{% block content %}101<section>102<h1 class="display-4">Retrieve Off Day</h1>103<div>104<table class="table table-striped">105    <title>Off Days</title>106    <thead>107      <tr>108        <th>Start</th>109        <th>End</th>110        <th>Reason/Message</th>111        <th></th>112        <th><a href="/editOffDay" class="btn btn-warning">Add</a></th>113      </tr>114    </thead>115    <tbody>116    {% for id in off_day_dict %}117      <tr>118        <td>{{ off_day_dict[id].get_start() }}</td>119        <td>{{ off_day_dict[id].get_end() }}</td>120        <td>{{ off_day_dict[id].get_reason() }}</td>121        <td><a href="/updateOffDay/{{ id }}/" class="btn btn-warning">Update</a></td>122        <td>123          <form action="{{url_for('delete_off_day', id=off_day_dict[id].get_id())}}" method="POST">124            <input type="submit" value="Delete" class="btn btn-danger">125          </form>126        </td>127      </tr>128    {% endfor %}129    </tbody>130  </table>131</div>132</section>...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!!
