Beispiel #1
0
 def saveData(self, data):
     start_date = str(datetime.datetime.now())
     items = data['stations']
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(
                 self.buildRecord(item, start_date).toJSON())
 def saveData(self, data):
     items = data['response']['body']['resultat']['actes']['acte']
     if len(items) >= 0:
         for index, item in enumerate(items):
             record=self.buildRecord(item)
             if(record is not None):
                 StorageHelper().store(record.toJSON())
Beispiel #3
0
 def saveData(self, data, provider, sensor):
     if (sensor['type'] == 'noise'):
         try:
             StorageHelper().store(
                 self.buildRecord(data, provider, sensor).toJSON())
         except Exception as e:
             print(str(datetime.datetime.now()) + ' ERROR ' + str(e))
Beispiel #4
0
 def saveData(self, data, component_id=0):
     total = 0
     items = data['data']['participatoryProcess']['components'][component_id]['meetings']['edges']
     if len(items) >= 0:
         for index, item in enumerate(items):
             if item['node'] != None:
                 StorageHelper().store(self.buildRecord(item['node']).toJSON())
                 total += 1
     return total
Beispiel #5
0
 def saveData(self, data, community_id):
     total = 0
     #print (data)
     item = data.copy()
     del item['sensors']
     for sensor in data['sensors']:
         if (sensor['description'] != 'Humidity'): StorageHelper().store(self.buildRecord({**item, **sensor},community_id).toJSON(),False)
         total +=1 
     return total
Beispiel #6
0
 def saveData(self, data, rID):
     total = 0
     items = data
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(
                 self.buildRecord(item, rID, str(index)).toJSON())
             total += 1
     return total
 def saveData(self, data):
     items = data
     if len(items.index) >= 0:
         for index, item in items.iterrows():
             StorageHelper().store(self.buildRecord(item).toJSON())
Beispiel #8
0
 def saveData(self, data):
     items = data['result']['records']
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(self.buildRecord(item).toJSON())
 def saveData(self, data, provider, sensor):
     StorageHelper().store(
         self.buildRecord(data, provider, sensor).toJSON())
Beispiel #10
0
 def saveData(self, data, type):
     print(data)
     items = data['features']
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(self.buildRecord(item, type).toJSON())
Beispiel #11
0
 def saveData(self, data, sensor):
     items = data
     if 'readings' in data:
         for item in reversed(data['readings']):
             StorageHelper().store(self.buildRecord(item, sensor).toJSON())
Beispiel #12
0
 def saveData(self, data, type=''):
     items = data['rdf:RDF']['v:VCard']
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(self.buildRecord(item, type).toJSON())
    def start(self, base, source_name=None, districts=None):

        print(str(datetime.datetime.now()) + ' ' + 'Start collection')
        dddc_api_url = base['dddc_api_url']
        query = base['query']
        response = requests.post(dddc_api_url, data = {'query': query}, headers={'accept': 'application/json'})

        petition = response.json()['data']['petition']
        print (petition)
        petition_id = petition['attribute_id']
        credential_issuer_api_url = petition['credential_issuer_api_url']

        json_attribute_info_optional = petition['json_attribute_info_optional']
        hashed_bins = {}
        for attribute in json_attribute_info_optional:
            value_set = attribute['value_set']
            for value in value_set:
                result, _ = zenroom.execute(script="print(ECDH.kdf(HASH.new('sha512'), str(DATA)))".encode(), keys=None, data=value.encode())
                hashed_bins[result.decode()] = value

        credentials_url = base['credentials_url']
        response = requests.get(credentials_url+'/stats/', headers={'accept': 'application/json'})
        stats = response.json()
        item_count = 0
        total = stats['total']
        del stats['total']
        for attribute in stats:
            attribute_stats = stats[attribute]
            attribute_total_count = 0
            for attribute_stat in attribute_stats:
                attribute_value = list(attribute_stat.keys())[0]
                attribute_count = attribute_stat[attribute_value]
                if attribute_value in hashed_bins:
                    attribute_total_count += attribute_count
                    for i in range(attribute_count):
                        item = {}
                        item['id'] = petition_id + '-' + str(item_count)
                        item['petitionId'] = petition_id
                        item['age'] = None
                        item['gender'] = None
                        item['district'] = None
                        if 'district' == attribute:
                            item[attribute] = districts[str(hashed_bins[attribute_value])]
                        else:
                            item[attribute] = hashed_bins[attribute_value]
                        print (item)
                        StorageHelper().store(self.buildCredentialRecord(item).toJSON())
                        item_count += 1
            # fill with not provided data
            #for i in range(total-attribute_total_count):
            #    item = {}
            #    item['id'] = petition_id + '-' + str(item_count)
            #    item['petitionId'] = petition_id
            #    item['age'] = None
            #    item['gender'] = None
            #    item['district'] = None
            #    item[attribute] = 'not provided'
            #    StorageHelper().store(self.buildCredentialRecord(item).toJSON())
            #    item_count += 1

        print(str(datetime.datetime.now()) + ' ' + '         Total: ' + str("{0:0>9}".format(total)))
        print(str(datetime.datetime.now()) + ' ' + 'End collection')

        for petition_id in collectorCfg['collectors']['decidim'][source_name]['petitions_ids']:

            petitions_url = collectorCfg['collectors']['decidim'][source_name]['petitions_url']
            dddc_username = collectorCfg['collectors']['decidim'][source_name]['dddc_username']
            dddc_password = collectorCfg['collectors']['decidim'][source_name]['dddc_password']

            print ('----------------------')
            print ('Token:')
            response = requests.post(petitions_url+'/token', data = 'grant_type=&username='******'&password='******'&scope=&client_id=&client_secret=', headers={'accept': 'application/json' , 'content-type' : 'application/x-www-form-urlencoded'})
            access_token = response.json()['access_token']
            print (access_token)
            print ('----------------------')
            print ('Count:')
            response = requests.post(petitions_url+'/petitions/'+petition_id+'/count', headers={'authorization' : 'Bearer ' + access_token ,'accept': 'application/json' , 'content-type' : 'application/json'})
            count = response.json()
            print (count)
            print ('----------------------')
            print ('Get (Expanded):')
            response = requests.get(petitions_url+'/petitions/'+petition_id+'?expand=True', headers={'accept': 'application/json' , 'content-type' : 'application/json'})
            result = response.json()
            print (result)
            print ('----------------------')
            print ('Assert count:')
            tally = result['tally']
            petition = result['petition']
            print ('Executing contract from zenroom...')
            f = open('/tmp/tally.json', 'w')
            f.write(json.dumps(tally, indent=2))
            f.close()   
            f = open('/tmp/petition.json', 'w')
            f.write(json.dumps(petition, indent=2))
            f.close()   
            __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
            with open(os.path.join(__location__, '14-CITIZEN-count-petition.zencode')) as file:
                petition_count_zencode = file.read()
            command = 'zenroom -k /tmp/tally.json -a /tmp/petition.json -z ' + (os.path.join(__location__, '14-CITIZEN-count-petition.zencode'))
            assert_count = json.loads(subprocess.check_output(command.split()).decode("utf-8"))
            if (assert_count==count):
                print ( 'Everything was validated perfectly! Result:', str(assert_count['result']))
                for i in range(count['result']):
                    item = {}
                    item['id'] = petition_id + '-' + str(item_count)
                    item['petitionId'] = petition_id
                    StorageHelper().store(self.buildSignatureRecord(item).toJSON())
                    item_count += 1
            else:
                print ( 'Uh oh! Couldn\'t validate results')
Beispiel #14
0
 def saveData(self, data):
     StorageHelper().store(self.buildRecord(data).toJSON())
 def saveData(self, data, type=''):
     items = data['opendata']['list_items']['row']
     if len(items) >= 0:
         for index, item in enumerate(items):
             StorageHelper().store(self.buildRecord(item).toJSON())