Example #1
0
def probes(request):
    profiles = Profile.objects.all()
    for profile in profiles:
        probes = {}
        replicates = Replicate.objects.filter(profile=profile)
        for replicate in replicates:
            if replicate.probe_id not in probes:
                probes[replicate.probe_id] = [replicate.intensity]
            else:
                probes[replicate.probe_id].append(replicate.intensity)
        for id, intensities in probes.items():
            probe = Probe(name=id,
                          expression=sum(intensities) / len(intensities),
                          profile=profile)
            probes[id] = probe
        try:
            Probe.objects.bulk_create(probes.values())
        except Exception as e:
            print(str(e))
            try:
                for probe in probes:
                    probe.save()
            except Exception as e:
                print(str(e))
    print('Done!')
    #return redirect('/expressions/profiles/')
    return HttpResponse("Done")
Example #2
0
def probes(request):
    profiles = Profile.objects.all()
    for profile in profiles:
        probes = {}
        replicates = Replicate.objects.filter(profile=profile)
        for replicate in replicates:
            if replicate.probe_id not in probes:
                probes[replicate.probe_id] = [replicate.intensity]
            else:
                probes[replicate.probe_id].append(replicate.intensity)
        for id, intensities in probes.items():
            probe = Probe(name=id, expression=sum(intensities)/len(intensities), profile=profile)
            probes[id] = probe
        try:
            Probe.objects.bulk_create(probes.values())
        except Exception as e:
            print(str(e))
            try:
                for probe in probes:
                    probe.save()
            except Exception as e:
                print(str(e))
    print('Done!')
    #return redirect('/expressions/profiles/')
    return HttpResponse("Done")
Example #3
0
def parse_probe(dtg, addr, ssid):
    device = get_device(addr)
    
    recent = Device.objects(Q(events__timestamp__gte=datetime.utcnow() - timedelta(minutes=10)) | Q(events__ssid__ne=ssid), mac=addr)
    if len(recent) == 0:
        event = Probe()
        event.ssid = ssid
        event.timestamp = datetime.utcnow()
        device.events.append(event)
        device.save()
        
        dev = selector.select('Device', mac=addr).first()
        if dev == None:
            dev = Node('Device', mac=addr, last_seen=str(datetime.utcnow()), vendor=device.vendor)
            graph.create(dev)

        ss = selector.select('SSID', ssid=ssid).first()
        if ss == None:
            ss = Node('SSID', ssid=ssid, timestamp=str(datetime.utcnow()))
            graph.create(ss)

        if len(list(graph.match(start_node=dev, rel_type='probe', end_node=ss))) == 0:
            rel = Relationship(dev, 'probe', ss)
            graph.create(rel)
        
        print("%s[+] (%s) Probe: %s (%s) -> '%s'" % (Term.CYAN, dtg, addr, device.vendor, ssid))
Example #4
0
def insert_probe(enriched_probe):
    new_probe = Probe(mac=enriched_probe['mac'],
                      capture_time=enriched_probe['capture_time'],
                      vendor=enriched_probe['vendor'])
    session.add(new_probe)
    session.commit()
    print('insert')
Example #5
0
def get_currency_probes():
	user_agent = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; hu-HU; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'}
	page = requests.get('http://halykbank.kz/ru/currency-rates', headers=user_agent)
	tree = html.fromstring(page.content)
	
	last_d_probe = Probe.objects.filter(currency=0).latest('date')
	last_r_probe = Probe.objects.filter(currency=1).latest('date')
	
	d_buy = float(tree.xpath('//div[@class="main-text"]/table/tbody/tr[2]/td[2]/text()')[0].replace(',', '.'))
	d_sell = float(tree.xpath('//div[@class="main-text"]/table/tbody/tr[2]/td[3]/text()')[0].replace(',', '.'))
	r_buy = float(tree.xpath('//div[@class="main-text"]/table/tbody/tr[4]/td[2]/text()')[0].replace(',', '.'))
	r_sell = float(tree.xpath('//div[@class="main-text"]/table/tbody/tr[4]/td[3]/text()')[0].replace(',', '.'))
	
	if last_d_probe.buy != d_buy or last_d_probe.sell != d_sell:
		p = Probe(currency=0, buy=d_buy, sell=d_sell, date = datetime.now())
		p.save()
	if last_r_probe.buy != r_buy or last_r_probe.sell != r_sell:
		p = Probe(currency=1, buy=r_buy, sell=r_sell, date = datetime.now())
		p.save()