示例#1
0
 def setUp(self):
     u = User(username="******")
     u.save()
     d = Data()
     d.save()
     self.sylva_graph = Graph(name="mygraph", data=d, owner=u)
     self.sylva_graph.save()
示例#2
0
    def test__unicode(self):
        data = Data()
        data.date = timezone.now()
        data.value = '100%'
        data.indicator = 'test'

        self.assertEquals(unicode(data),
                          'test: 100% em 2010-10-10 00:00:00+00:00')
示例#3
0
 def setUp(self):
     self.u = User(username="******")
     self.u.save()
     d = Data()
     d.save()
     self.sylva_graph = Graph(name="mygraph", data=d, owner=self.u)
     self.sylva_graph.save()
     self.instanceName = "instanceRexster"
     self.instanceEngine = "engines.gdb.backends.rexster"
     self.instancePort = "7474"
     self.instancePath = "db/data"
示例#4
0
def make_random_data():
    new_data = Data()
    new_data.dust25 = random.randint(5, 200)
    new_data.dust100 = random.randint(5, 20)
    new_data.discomfort_index = random.randint(20, 60)
    new_data.co2 = random.randint(400, 1200)
    new_data.temp = random.randint(180, 230) / 10
    new_data.humid = random.randint(40, 50)
    new_data.device_id = str(random.randint(100000, 999999)) + "-" \
                         + str(random.randint(100000, 999999)) + "-" + \
                         str(random.randint(100000, 999999))
    new_data.save()
示例#5
0
def add_server(request):
    data_index_ip_address = request.META.get('REMOTE_ADDR')
    if request.method == "POST":
        try:
            data_operating_system = request.POST['operating_system']
            data_ip_address = request.POST['ip_address']
            data_system_port = request.POST['system_port']
            data_system_owner = request.POST['system_owner']
            data_system_username = request.POST['system_username']
            data_system_password = request.POST['system_password']
            data_system_description = request.POST['system_description']
            data_server_name = request.POST['server_name']
        except:

            log = "Add server POST data error|" + str(data_index_ip_address)  + "|" + str(
                datetime.datetime.now()) + " \n"
            logging.basicConfig(filename='logging/error.log', level=logging.DEBUG)
            logging.error(log)
        try:
            data = Data(
                operating_system=data_operating_system,
                ip_address=data_ip_address,
                system_port=data_system_port,
                system_owner=data_system_owner,
                system_username=data_system_username,
                system_password=data_system_password,
                system_description=data_system_description,
                server_name=data_server_name
            )
            data.save()
            log = "Add server|" + str(data_ip_address)+"|"+str(data_index_ip_address) +  "|" + str(
                datetime.datetime.now()) + " \n"
            logging.basicConfig(filename='logging/add_server.log', level=logging.DEBUG)
            logging.info(log)
        except:
            log = "Add server to save database error|" + str(data_index_ip_address) + "|" + str(
                datetime.datetime.now()) + " \n"
            logging.basicConfig(filename='logging/error.log', level=logging.DEBUG)
            logging.error(log)
        add_server_page="Add server:"+data_server_name
        return HttpResponse(add_server_page)
    return render(request,'add_server.html')
示例#6
0
def process_line(line, logFormat, load):

    def process_field(log_field):        
    
        def update_data(data):
            if "date" in (log_field.field.name).lower():
                data.date_field=value

            if "host" in (log_field.field.name).lower():
                data.host_field=value

            if "status" in (log_field.field.name).lower():
                data.status_field=value

            if "size" in (log_field.field.name).lower():
                try:
                    data.size_field=int(value)
                except:
                    data.size_field=0

            if "url" in (log_field.field.name).lower():
                data.url_field=value
                data.url_field_method=value.split(' ')[0]
                data.url_field_uri=value.split(' ')[1]
                data.url_field_protocol=value.split(' ')[2]                
            return data

        value = fields[log_field.position]
        if log_field.field.type == 2:
            value = datetime.strptime(fields[log_field.position], logFormat.date_format) 
            tz = pytz.timezone(settings.TIME_ZONE)
            value = tz.localize(value, is_dst=True)
        update_data(data)


    fields  = re.match( logFormat.regex, line).groups()
    log_fields = LogField.objects.filter(log_format=logFormat.pk).order_by("position")
    
    data = Data(load=load)    
    for log_field in log_fields:
        process_field(log_field)
    data.save()
示例#7
0
    async def parse_page(self, session: aiohttp.ClientSession,
                         page_num: int) -> List[Data]:
        """ парсит отдельную страницу вытаскивая id и ссылку на закупку """

        param = self.params.copy()
        param['pageNumber'] = page_num
        orders = []

        data = await self._get_request(session, self.search_link, params=param)
        doc = document_fromstring(data)
        for link in doc.xpath(
                '//div[@class="registry-entry__header-mid__number"]/a'):
            order_id = self._tender_id_handler(
                self._normalizer(link.xpath('./text()')[0]))
            order_link = self.main_link + link.xpath('./@href')[0]
            tender = Data()
            tender.id = order_id
            tender.tender_link = order_link
            orders.append(tender)
        return orders
示例#8
0
    def db_handler(self, id, data):
        session = self.session_maker()
        db_data = Data()
        db_data.id = id
        db_data.tender_price = self._tender_price_handler(data['tender_price'])
        db_data.type = data['type']
        db_data.tender_date = self._tender_date_handler(data['tender_date'])
        db_data.tender_object = data['tender_object']
        db_data.customer = data['customer']
        db_data.tender_adress = data['tender_adress']
        db_data.tender_delivery = data['tender_delivery']
        db_data.tender_terms = data['tender_term']
        db_data.document_links = '\n'.join(data['document_links'])
        db_data.tender_link = data['link']

        winner = Winners()
        winner.data_id = id
        winner.name = data['tender_winner'][0]
        winner.position = data['tender_winner'][1]
        winner.price = data['tender_winner'][2]
        db_data.winner.append(winner)

        for i in data['tender_object_info'][1:]:
            if len(i) == 6:
                data = Objects()
                data.position = i[0]
                data.name = i[1]
                data.unit = i[2]
                data.quantity = i[3]
                data.unit_price = i[4]
                data.price = i[5]
                db_data.objects.append(data)
        
        session.add(db_data)
        session.commit()
        db_data.winner = [winner]
        session.close()
        return db_data