Beispiel #1
0
    def update_indicator_data(self):

        base = os.path.dirname(os.path.abspath(__file__))
        location = base + "/data_backup/indicator_data.json"

        json_data = open(location)
        indicator_data = ujson.load(json_data)

        for d in indicator_data:
            try:
                indicator_name = d['indicator_name']
                country_iso = d['country_iso']

                value = d['value']
                year = d['year']

                if value == None or value == "NULL":
                    continue

                found_country = None
                if Country.objects.filter(code=country_iso).exists():
                    found_country = Country.objects.get(code=country_iso)
                else:
                    print "indicator not found for " + str(country_iso)
                    continue

                found_indicator = None
                if Indicator.objects.filter(id=indicator_name).exists():
                    found_indicator = Indicator.objects.get(id=indicator_name)
                else:
                    print "indicator not found for " + str(indicator_name)
                    continue

                if IndicatorData.objects.filter(indicator=found_indicator,
                                                country=found_country,
                                                year=year).exists():
                    continue

                new_indicator_data = IndicatorData(indicator=found_indicator,
                                                   country=found_country,
                                                   value=value,
                                                   year=year,
                                                   selection_type=None)
                new_indicator_data.save()

            except:
                print "error in update_indicator_data"

        print "ready"
        json_data.close()
Beispiel #2
0
    def update_indicator_data(self):

        base = os.path.dirname(os.path.abspath(__file__))
        location = base + "/data_backup/indicator_data.json"

        json_data = open(location)
        indicator_data = ujson.load(json_data)

        for d in indicator_data:
            try:
                indicator_name = d['indicator_name']
                country_iso = d['country_iso']

                value = d['value']
                year = d['year']


                if value == None or value == "NULL":
                    continue

                found_country = None
                if Country.objects.filter(code=country_iso).exists():
                        found_country = Country.objects.get(code=country_iso)
                else:
                    print "indicator not found for " + str(country_iso)
                    continue

                found_indicator = None
                if Indicator.objects.filter(id=indicator_name).exists():
                        found_indicator = Indicator.objects.get(id=indicator_name)
                else:
                    print "indicator not found for " + str(indicator_name)
                    continue

                if IndicatorData.objects.filter(indicator=found_indicator, country=found_country, year=year).exists():
                    continue

                new_indicator_data = IndicatorData(indicator=found_indicator, country=found_country, value=value, year=year, selection_type=None)
                new_indicator_data.save()

            except:
                print "error in update_indicator_data"

        print "ready"
        json_data.close()
    def add_indicator_data(self):
        BASE = os.path.dirname(os.path.abspath(__file__))
        specific = BASE + "/data_backup/wdi_data/WDI_Data.csv"

        with open(specific, 'rb') as f:
            data_reader = csv.reader(f)
            data_header = next(data_reader)
            for row in data_reader:
                indicator_code = row[data_header.index("Indicator Code")]
                our_indicator = self.get_indicator_or_create(indicator_code)
                iso3 = row[data_header.index("Country Code")]
                our_country = self.get_country(iso3)
                if not our_country:
                    our_region = self.get_region(iso3)

                our_values = self.get_values_for_years(row)
                if len(our_values) >= 1:
                    for item in our_values:
                        our_data = IndicatorData()
                        our_data.indicator = our_indicator
                        our_data.year = data_header[item[0]]
                        our_data.value = item[1]
                        our_data.country = our_country
                        our_data.save()
Beispiel #4
0
    def add_indicator_data(self):
        BASE = os.path.dirname(os.path.abspath(__file__))
        specific = BASE + "/data_backup/wdi_data/WDI_Data.csv"

        with open(specific, 'rb') as f:
            data_reader = csv.reader(f)
            data_header = data_reader.next()
            for row in data_reader:
                indicator_code = row[data_header.index("Indicator Code")]
                our_indicator = self.get_indicator_or_create(indicator_code)
                iso3 = row[data_header.index("Country Code")]
                our_country = self.get_country(iso3)
                if not our_country:
                    our_region = self.get_region(iso3)

                our_values = self.get_values_for_years(row)
                if len(our_values) >= 1:
                    for item in our_values:
                        our_data = IndicatorData()
                        our_data.indicator = our_indicator
                        our_data.year = data_header[item[0]]
                        our_data.value = item[1]
                        our_data.country = our_country
                        our_data.save()
Beispiel #5
0
    def update_indicator_city_data(self):

        base = os.path.dirname(os.path.abspath(__file__))
        location = base + "/data_backup/indicator_city_data.json"
        location2 = base + "/data_backup/indicator_city_info.json"
        json_data = open(location)
        indicator_data_set = ujson.load(json_data)
        json_data2 = open(location2)
        city_info_set = ujson.load(json_data2)

        for d in indicator_data_set:
            try:
                indicator_id = d['indicator_id']
                city_id = d['city_id']
                city_name = "unknown"
                value = d['value']
                year = d['year']

                if value == None or value == "NULL":
                    continue

                found_city = None

                for c in city_info_set:
                    if (c['id'] == city_id):
                        city_name = c['name']
                        country_id = c['country_id']

                        if City.objects.filter(name=city_name,
                                               country_id=country_id).exists():
                            found_city = City.objects.get(
                                name=city_name, country_id=country_id)
                        elif City.objects.filter(
                                ascii_name=city_name,
                                country_id=country_id).exists():
                            found_city = City.objects.get(
                                ascii_name=city_name, country_id=country_id)
                        elif City.objects.filter(
                                alt_name=city_name,
                                country_id=country_id).exists():
                            found_city = City.objects.get(
                                alt_name=city_name, country_id=country_id)
                        elif City.objects.filter(
                                namepar=city_name,
                                country_id=country_id).exists():
                            found_city = City.objects.get(
                                namepar=city_name, country_id=country_id)

                if not found_city:
                    print "city not found for " + str(city_id)
                    continue

                found_indicator = None
                if Indicator.objects.filter(id=indicator_id).exists():
                    found_indicator = Indicator.objects.get(id=indicator_id)
                else:
                    print "indicator not found for " + str(indicator_id)
                    continue

                if IndicatorData.objects.filter(indicator=found_indicator,
                                                city=found_city,
                                                year=year).exists():
                    continue

                new_indicator_data = IndicatorData(indicator=found_indicator,
                                                   city=found_city,
                                                   value=value,
                                                   year=year,
                                                   selection_type=None)
                new_indicator_data.save()

            except Exception as e:
                print "error in update_indicator_data"

        print "ready"

        json_data.close()
        json_data2.close()
Beispiel #6
0
    def update_indicator_city_data(self):

         base = os.path.dirname(os.path.abspath(__file__))
         location = base + "/data_backup/indicator_city_data.json"
         location2 = base + "/data_backup/indicator_city_info.json"
         json_data = open(location)
         indicator_data_set = ujson.load(json_data)
         json_data2 = open(location2)
         city_info_set = ujson.load(json_data2)

         for d in indicator_data_set:
            try:
                indicator_id = d['indicator_id']
                city_id = d['city_id']
                city_name = "unknown"
                value = d['value']
                year = d['year']

                if value == None or value == "NULL":
                    continue

                found_city = None

                for c in city_info_set:
                    if (c['id'] == city_id):
                        city_name = c['name']
                        country_id = c['country_id']

                        if City.objects.filter(name=city_name, country_id=country_id).exists():
                            found_city = City.objects.get(name=city_name, country_id=country_id)
                        elif City.objects.filter(ascii_name=city_name, country_id=country_id).exists():
                                found_city = City.objects.get(ascii_name=city_name, country_id=country_id)
                        elif City.objects.filter(alt_name=city_name, country_id=country_id).exists():
                                found_city = City.objects.get(alt_name=city_name, country_id=country_id)
                        elif City.objects.filter(namepar=city_name, country_id=country_id).exists():
                                found_city = City.objects.get(namepar=city_name, country_id=country_id)

                if not found_city:
                    print "city not found for " + str(city_id)
                    continue

                found_indicator = None
                if Indicator.objects.filter(id=indicator_id).exists():
                        found_indicator = Indicator.objects.get(id=indicator_id)
                else:
                    print "indicator not found for " + str(indicator_id)
                    continue

                if IndicatorData.objects.filter(indicator=found_indicator, city=found_city, year=year).exists():
                    continue

                new_indicator_data = IndicatorData(indicator=found_indicator, city=found_city, value=value, year=year, selection_type=None)
                new_indicator_data.save()

            except Exception as e:
                print "error in update_indicator_data"

         print "ready"

         json_data.close()
         json_data2.close()