def dict_insert(cursor, table, data): query = "INSERT INTO " + table + "(" + ", ".join( data.keys()) + ") VALUES (:" + ", :".join(data.keys()) + ")" try: return cursor.execute(query, data) except: print "Query failure! Query was:", query return None
def test_render_taal_detail(self): s = api.TaalDetailSerializer(self.t) data = json.loads(JSONRenderer().render(s.data)) expected = [ 'aliases', 'common_name', 'composers', 'name', 'recordings', 'uuid' ] self.assertEqual(expected, sorted(data.keys()))
def test_render_form_detail(self): s = api.FormDetailSerializer(self.f) data = json.loads(JSONRenderer().render(s.data).decode("utf-8")) expected = [ 'aliases', 'artists', 'common_name', 'name', 'recordings', 'uuid' ] self.assertEqual(expected, sorted(data.keys()))
def test_render_artist_detail(self): response = self.apiclient.get( "/api/makam/artist/a484bcbc-c0d9-468a-952c-9938d5811f85") data = response.data keys = sorted(data.keys()) self.assertEqual(["instruments", "mbid", "name", "releases"], keys)
def dict_insert(cursor, table, data): query = "INSERT INTO " + table + "(" + ", ".join(data.keys()) + ") VALUES (:" + ", :".join(data.keys()) + ")" try: return cursor.execute(query, data) except: print "Query failure! Query was:", query return None
def test_render_raag_detail(self): s = api.RaagDetailSerializer(self.r) data = json.loads(JSONRenderer().render(s.data)) expected = [ 'aliases', 'artists', 'common_name', 'composers', 'name', 'uuid' ] self.assertEqual(expected, sorted(data.keys()))
def test_render_taala_detail(self): client = APIClient() client.force_authenticate(user=self.normaluser) response = client.get("/api/carnatic/taala/d5285bf4-c3c5-454e-a659-fec30075990b") data = response.data fields = ['aliases', 'artists', 'common_name', 'composers', 'name', 'recordings', 'uuid', 'works'] self.assertEqual(fields, sorted(data.keys()))
def test_render_release_detail(self): s = api.ReleaseDetailSerializer(self.r) data = json.loads(JSONRenderer().render(s.data).decode("utf-8")) expected = [ 'artists', 'image', 'mbid', 'recordings', 'release_artists', 'title', 'year' ] self.assertEqual(expected, sorted(data.keys()))
def generate_languages_info_file(data): file = open(INFO_FILENAME, 'w') lines = [] for k in sorted(data.keys()): lines.append("{0:6} : {1},\n".format('"'+k+'"', '"'+data[k]+'"')) file.writelines(lines) file.close()
def test_render_recording_detail(self): client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get("/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24") data = response.data fields = ['album_artists', 'artists', 'concert', 'form', 'length', 'mbid', 'raaga', 'taala', 'title', 'work'] self.assertEqual(fields, sorted(data.keys()))
def test_render_work_detail(self): client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get("/api/carnatic/work/7ed898bc-fa11-41ae-b1c9-913d96c40e2b") data = response.data fields = ['composers', 'lyricists', 'mbid', 'raagas', 'recordings', 'taalas', 'title'] self.assertEquals(fields, sorted(data.keys()))
def test_render_taala_inner(self): s = api.TaalaInnerSerializer(self.taala) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(["name", "uuid"], sorted(data.keys())) try: uuid.UUID(data["uuid"]) except ValueError: self.fail("uuid is not correct/present")
def test_render_raaga_inner(self): s = api.RaagaInnerSerializer(self.raaga) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(["name", "uuid"], sorted(data.keys())) try: uuid.UUID(data["uuid"]) except ValueError: self.fail("uuid is not correct/present")
def test_render_taala_detail(self): response = self.apiclient.get( "/api/carnatic/taala/d5285bf4-c3c5-454e-a659-fec30075990b") data = response.data fields = [ 'aliases', 'artists', 'common_name', 'composers', 'name', 'recordings', 'uuid', 'works' ] self.assertEqual(fields, sorted(data.keys()))
def test_render_taala_inner(self): s = api.TaalaInnerSerializer(self.taala) data = json.loads(JSONRenderer().render(s.data).decode("utf-8")) self.assertEqual(["common_name", "name", "uuid"], sorted(data.keys())) try: uuid.UUID(data["uuid"]) except ValueError: self.fail("uuid is not correct/present")
def test_render_artist_detail(self): client = APIClient() client.force_authenticate(user=self.normaluser) response = client.get("/api/carnatic/artist/a484bcbc-c0d9-468a-952c-9938d5811f85") data = response.data keys = sorted(data.keys()) self.assertEqual(["concerts", "instruments", "mbid", "name", "recordings"], keys)
def test_render_raaga_inner(self): s = api.RaagaInnerSerializer(self.raaga) data = json.loads(JSONRenderer().render(s.data).decode("utf-8")) self.assertEqual(["common_name", "name", "uuid"], sorted(data.keys())) try: uuid.UUID(data["uuid"]) except ValueError: self.fail("uuid is not correct/present")
def _step_fn(self, step, inputs): # Forward pass and loss with torch.no_grad(): loss, data = utils.forward_pass(self.model, self.loss_fn, inputs) print(list(data.keys())) print(f"loss {loss.item():.3f}") self._debug_step(loss, data)
def get_longest_state(data): """Receives data, which can be the us_state_abbrev dict or the states list (see above). It returns the longest state measured by the length of the string""" if isinstance(data, list): states_dict = {len(state): state for state in data} return states_dict[max(states_dict.keys())] else: states_dict = {len(state): state for state in data.keys()} return states_dict[max(states_dict.keys())] pass
def test_render_artist_detail(self): client = APIClient() client.force_authenticate(user=self.normaluser) response = client.get( "/api/carnatic/artist/a484bcbc-c0d9-468a-952c-9938d5811f85") data = response.data keys = sorted(data.keys()) self.assertEqual( ["concerts", "instruments", "mbid", "name", "recordings"], keys)
def test_render_raaga_detail(self): client = APIClient() client.force_authenticate(user=self.normaluser) response = client.get( "/api/carnatic/raaga/d5285bf4-c3c5-454e-a659-fec30075990b") data = response.data fields = [ 'aliases', 'artists', 'common_name', 'composers', 'name', 'recordings', 'uuid', 'works' ] self.assertEqual(fields, sorted(data.keys()))
def test_render_concert_detail(self): s = api.ConcertDetailSerializer(self.cnormal) data = json.loads(JSONRenderer().render(s.data)) fields = ['artists', 'concert_artists', 'image', 'mbid','recordings', 'title', 'year'] self.assertEqual(fields, sorted(data.keys())) recordings = data["recordings"] self.assertEqual(1, len(recordings)) r = recordings[0] expected = {"title": "normal recording", "mbid": "34275e18-0aef-4fa5-9618-b5938cb73a24", "disc": 1, "track": 1, "disctrack": 1} self.assertEqual(expected, r)
def test_render_work_detail(self): client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get( "/api/carnatic/work/7ed898bc-fa11-41ae-b1c9-913d96c40e2b") data = response.data fields = [ 'composers', 'lyricists', 'mbid', 'raagas', 'recordings', 'taalas', 'title' ] self.assertEqual(fields, sorted(data.keys()))
def test_render_recording_detail(self): client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get( "/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24") data = response.data fields = [ 'album_artists', 'artists', 'concert', 'form', 'length', 'mbid', 'raaga', 'taala', 'title', 'work' ] self.assertEqual(fields, sorted(data.keys()))
def __impl__(): # one time read batch_size * count data for rnn for data in reader(): inst_num_per_part = batch_size split_data = {} len_check = True for k in data.keys(): if data[k] is not None: if len(data[k]) != batch_size * count: len_check = False print("data check error!!, data=" + data[k] + ", k=" + k) break if len_check: res = [] for i in range(count): split_data = {} for k in data.keys(): if data[k] is not None: split_data[k] = data[k][inst_num_per_part * i:inst_num_per_part * (i + 1)] res.append(split_data) yield res
def drawPlane(data, firstname, lastname): print("Generating swing plane for " + firstname.title() + " " + lastname.title() + ":") fig = plt.figure(figsize=(6, 6)) ax = fig.add_subplot(111, polar=True) ax.bar(data.keys().tolist(), data.tolist(), color='red', width=.075, linewidth=0.1, label='Hits') ax.set_thetamin(-80) ax.set_thetamax(80) ax.legend() plt.show()
async def visual(ctx, v_type, country): if v_type in visual_types and country in countries: if v_type == 'pie': c_data = virus_data[country] labels = ['Active: %i'%(c_data[5]), 'Recovered: %i'%(c_data[1]), 'Dead: %i'%(c_data[2])] sizes = [c_data[5], c_data[1], c_data[2]] colors = ['yellowgreen', 'gold', 'lightskyblue'] fig = plt.figure(facecolor = 'dimgrey', edgecolor='k', linewidth= 2.0, frameon=True) pie = plt.pie(sizes,colors = colors , autopct='%1.1f%%', shadow = False, startangle=90) plt.legend(pie[0], labels, loc="best") plt.axis('equal') plt.tight_layout() plt.savefig('pie.png', facecolor=fig.get_facecolor()) await ctx.send(file=discord.File('pie.png')) elif v_type == 'line': http = urllib3.PoolManager() response = http.request('GET','https://api.thevirustracker.com/free-api?countryTimeline=%s'%(country)) data = response.data #byte data = data.decode('utf8') #converting byte to string data = json.loads(data) data = data['timelineitems'][0] dates = list(data.keys()) values = [] for x in data.keys(): if x != 'stat' : values.append(data[x]["total_cases"]) dates = dates[:len(dates) -1:] fig = plt.figure(figsize = (80,20)) plt.plot(dates,values, color="#ff0000", linewidth=3) plt.gcf().autofmt_xdate() plt.grid() plt.savefig('plt.png') await ctx.send(file=discord.File('plt.png')) else: await ctx.send("Invalid visual")
def test_recording_detail_restr_collection(self): """ Only staff can access a recording from restricted collections""" client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get("/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24") data = response.data self.assertEqual(200, response.status_code) fields = ['album_artists', 'artists', 'concert', 'form', 'length', 'mbid', 'raaga', 'taala', 'title', 'work'] self.assertEqual(fields, sorted(data.keys())) # If we request another collection over the header parameter # we get a 404 client.force_authenticate(user=self.normaluser) response = client.get("/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24", **{'HTTP_DUNYA_COLLECTION':'afd6'}) self.assertEqual(404, response.status_code)
def population_statistics(feature_description, data1, treatment, target, threshold, is_above, statistic_functions): print(feature_description) dic = {} for key in list(data1.keys()): dic.setdefault(key, []) if is_above: for row, value in enumerate(data1[treatment]): if value > threshold: for key in list(data.keys()): dic[key].append(data1[key][row]) else: for row, value in enumerate(data1[treatment]): if value <= threshold: for key in list(data1.keys()): dic[key].append(data1[key][row]) data.print_details(dic, [target], statistic_functions)
def save_output(data): files = sorted(list(data.keys())) amus = sorted(list(data[files[0]].keys())) intData = pd.DataFrame(columns=amus, index=files) sigData = pd.DataFrame(columns=amus, index=files) for file in files: for amu in amus: intData[amu][file] = data[file][amu]['integral'] sigData[amu][file] = data[file][amu]['signal'] filename = appmodel.datafolder + ".xlsx" savepath = os.path.join(APP_ROOT, "output", filename) writer = pd.ExcelWriter(savepath, engine='xlsxwriter') intData.to_excel(writer, sheet_name="Integral") sigData.to_excel(writer, sheet_name="Signal") writer.save()
def __init__(self, user_id, group_id, app_id='@app', fields=None, data={}, params=None): params = params or {} if fields: params['fields'] = ','.join(fields) else: params['fields'] = ','.join(data.keys()) params['data'] = data #TODO: add support for rest params.update({'userId': user_id, 'groupId': group_id, 'appId': app_id}) rpc_request = RpcRequestInfo('appdata.update', params=params) super(UpdateAppDataRequest, self).__init__(None, rpc_request, user_id)
def load_benchmarks(filename): Benchmark = namedtuple('Benchmark', 'name, teff, e_teff, e_logg, e_feh, logg, feh, abundances') with open(filename, "r") as fp: data = yaml.load(fp) # For each star, clean up the abundances into the right format. benchmarks = [] for name in data.keys(): cleaned_abundances = {} for species, abundance_info in data[name].get("abundances", {}).items(): try: abundance_info = float(abundance_info) except: # Some uncertainty in it? abundance_info = abundance_info.split() mean, sigma = map(float, (abundance_info[0], abundance_info[-1])) else: mean, sigma = abundance_info, np.nan cleaned_abundances[species] = (mean, sigma) kwds = data[name].copy() things = ("teff", "logg", "feh") for thing in things: if thing in kwds: v, e = map(float, kwds[thing].split()) kwds[thing] = v kwds["e_{}".format(thing)] = e kwds.setdefault("teff", np.nan) kwds.setdefault("logg", np.nan) kwds.setdefault("feh", np.nan) kwds.update({ "name": name, "abundances": cleaned_abundances, }) benchmarks.append(Benchmark(**kwds)) return benchmarks
def test_render_concert_detail(self): s = api.ConcertDetailSerializer(self.cnormal) data = json.loads(JSONRenderer().render(s.data).decode("utf-8")) fields = [ 'artists', 'concert_artists', 'image', 'mbid', 'recordings', 'title', 'year' ] self.assertEqual(fields, sorted(data.keys())) recordings = data["recordings"] self.assertEqual(1, len(recordings)) r = recordings[0] expected = { "title": "normal recording", "mbid": "34275e18-0aef-4fa5-9618-b5938cb73a24", "disc": 1, "track": 1, "disctrack": 1 } self.assertEqual(expected, r)
def test_recording_detail_restr_collection(self): """ Only staff can access a recording from restricted collections""" client = APIClient() client.force_authenticate(user=self.staffuser) response = client.get( "/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24") data = response.data self.assertEqual(200, response.status_code) fields = [ 'album_artists', 'artists', 'concert', 'form', 'length', 'mbid', 'raaga', 'taala', 'title', 'work' ] self.assertEqual(fields, sorted(data.keys())) # If we request another collection over the header parameter # we get a 404 client.force_authenticate(user=self.normaluser) response = client.get( "/api/carnatic/recording/34275e18-0aef-4fa5-9618-b5938cb73a24", **{'HTTP_DUNYA_COLLECTION': str(uuid.uuid4())}) self.assertEqual(404, response.status_code)
def __init__(self, user_id, group_id, app_id='@app', fields=None, data={}, params=None): params = params or {} if fields: params['fields'] = ','.join(fields) else: params['fields'] = ','.join(data.keys()) params['data'] = data #TODO: add support for rest params.update({ 'userId': user_id, 'groupId': group_id, 'appId': app_id }) rpc_request = RpcRequestInfo('appdata.update', params=params) super(UpdateAppDataRequest, self).__init__(None, rpc_request, user_id)
def test_render_laya_detail(self): s = api.LayaDetailSerializer(self.l) data = json.loads(JSONRenderer().render(s.data)) expected = ['aliases', 'common_name', 'name', 'recordings', 'uuid'] self.assertEqual(expected, sorted(data.keys()))
def test_render_symbtr_detail(self): s = api.SymbtrDetailSerializer(self.s) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["name", "uuid"], sorted(data.keys()))
def test_render_usul_detail(self): s = api.UsulDetailSerializer(self.u) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["gazels", "name", "taksims", "uuid", "works"], sorted(data.keys()))
def test_render_makam_detail(self): s = api.MakamDetailSerializer(self.m) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals( ["gazels", "name", "symtr_key", "taksims", "uuid", "works"], sorted(data.keys()))
def test_render_instrument_detail(self): s = api.InstrumentDetailSerializer(self.i1) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["artists", "mbid", "name"], sorted(data.keys())) self.assertEquals(1, len(data["artists"]))
def test_render_instrument_inner(self): s = api.InstrumentInnerSerializer(self.i) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(['mbid', 'name'], sorted(data.keys()))
def test_render_recording_inner(self): s = api.RecordingInnerSerializer(self.rnormal) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["mbid", "title"], sorted(data.keys()))
def test_render_concert_inner(self): s = api.ConcertInnerSerializer(self.cnormal) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(["mbid", "title"], sorted(data.keys()))
def test_render_form_detail(self): s = api.FormDetailSerializer(self.f) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["name", "uuid", "works"], sorted(data.keys()))
def test_render_usul_list(self): s = api.UsulInnerSerializer(self.u) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["name", "uuid"], sorted(data.keys()))
def test_render_work_inner(self): w = models.Work(title="work", mbid="") s = api.WorkInnerSerializer(w) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["mbid", "title"], sorted(data.keys()))
def test_render_release_inner(self): s = api.ReleaseInnerSerializer(self.r) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(['mbid', 'title'], sorted(data.keys()))
def test_render_release_detail(self): s = api.ReleaseDetailSerializer(self.r) data = json.loads(JSONRenderer().render(s.data)) expected = ['artists', 'image', 'mbid', 'recordings', 'release_artists', 'title', 'year'] self.assertEqual(expected, sorted(data.keys()))
def test_render_makam_detail(self): s = api.MakamDetailSerializer(self.m) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["gazels", "name", "symtr_key", "taksims", "uuid", "works"], sorted(data.keys()))
def test_render_instrument_detail(self): s = api.InstrumentDetailSerializer(self.i) data = json.loads(JSONRenderer().render(s.data)) expected = ['artists', 'mbid', 'name'] self.assertEqual(expected, sorted(data.keys()))
def test_render_composer_inner(self): mbid = uuid.uuid4() c = models.Composer.objects.create(name="Composer", mbid=mbid) s = api.ComposerInnerSerializer(c) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["mbid", "name"], sorted(data.keys()))
def test_render_instrument_list(self): s = api.InstrumentInnerSerializer(self.i1) data = json.loads(JSONRenderer().render(s.data)) self.assertEquals(["mbid", "name"], sorted(data.keys()))
def test_render_artist_detail(self): response = self.apiclient.get("/api/makam/artist/a484bcbc-c0d9-468a-952c-9938d5811f85") data = response.data keys = sorted(data.keys()) self.assertEqual(["instruments", "mbid", "name", "releases"], keys)
def test_render_raag_detail(self): s = api.RaagDetailSerializer(self.r) data = json.loads(JSONRenderer().render(s.data)) expected = ['aliases', 'artists', 'common_name', 'composers', 'name', 'recordings', 'uuid'] self.assertEqual(expected, sorted(data.keys()))
def test_render_laya_inner(self): s = api.LayaInnerSerializer(self.l) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(['common_name', 'name', 'uuid'], sorted(data.keys()))
def test_render_work_inner(self): s = api.WorkInnerSerializer(self.wnormal) data = json.loads(JSONRenderer().render(s.data)) self.assertEqual(['mbid', 'title'], sorted(data.keys()))