Ejemplo n.º 1
0
 def competitions(self, data_frame):
     if 'country' in data_frame.columns:
         lambdafunc = lambda x: pd.Series(self.get_id(Countries, name=x['country']))
         id_frame = data_frame.apply(lambdafunc, axis=1)
         id_frame.columns = ['country_id']
     elif 'confederation' in data_frame.columns:
         lambdafunc = lambda x: pd.Series(ConfederationType.from_string(x['confed']))
         id_frame = data_frame.apply(lambdafunc, axis=1)
         id_frame.columns = ['confederation']
     else:
         print "Cannot insert Competition record: No Country or Confederation data present"
     return data_frame.join(id_frame)
Ejemplo n.º 2
0
 def parse_file(self, rows):
     insertion_list = []
     print "Ingesting Countries..."
     for keys in rows:
         country_name = "{name}".format(**keys).strip().decode('utf-8')
         confederation = "{confederation}".format(**keys).strip()
         if not self.record_exists(Countries, name=country_name):
             insertion_list.append(Countries(
                     name=country_name, confederation=ConfederationType.from_string(confederation)))
             if len(insertion_list) == 50:
                 self.session.add_all(insertion_list)
                 self.session.commit()
                 insertion_list = []
     if len(insertion_list) != 0:
         self.session.add_all(insertion_list)
     print "Country Ingestion complete."
Ejemplo n.º 3
0
 def parse_file(self, rows):
     insertion_list = []
     print "Ingesting Countries..."
     for keys in rows:
         country_name = self.column_unicode("name", **keys)
         country_code = self.column("code", **keys)
         confederation = self.column("confederation", **keys)
         if not self.record_exists(Countries, name=country_name):
             insertion_list.append(Countries(
                 name=country_name, code=country_code,
                 confederation=ConfederationType.from_string(confederation)))
             if len(insertion_list) == 50:
                 self.session.add_all(insertion_list)
                 self.session.commit()
                 insertion_list = []
     if len(insertion_list) != 0:
         self.session.add_all(insertion_list)
     print "Country Ingestion complete."
Ejemplo n.º 4
0
 def parse_file(self, rows):
     insertion_list = []
     print "Ingesting Timezones..."
     for keys in rows:
         timezone_region = self.column_unicode("name", **keys)
         confederation = self.column("confederation", **keys)
         offset = self.column_float("offset", **keys)
         if not self.record_exists(Timezones, name=timezone_region):
             insertion_list.append(Timezones(
                     name=timezone_region, offset=offset,
                     confederation=ConfederationType.from_string(confederation)))
             if len(insertion_list) == 50:
                 self.session.add_all(insertion_list)
                 self.session.commit()
                 insertion_list = []
     if len(insertion_list) != 0:
         self.session.add_all(insertion_list)
     print "Timezone Ingestion complete."
Ejemplo n.º 5
0
 def parse_file(self, rows):
     insertion_list = []
     print "Ingesting Timezones..."
     for keys in rows:
         timezone_region = "{name}".format(**keys).strip().decode('utf-8')
         confederation = "{confederation}".format(**keys).strip()
         offset = float("{offset}".format(**keys).strip())
         if not self.record_exists(Timezones, name=timezone_region):
             insertion_list.append(Timezones(
                     name=timezone_region, offset=offset,
                     confederation=ConfederationType.from_string(confederation)))
             if len(insertion_list) == 50:
                 self.session.add_all(insertion_list)
                 self.session.commit()
                 insertion_list = []
     if len(insertion_list) != 0:
         self.session.add_all(insertion_list)
     print "Timezone Ingestion complete."
Ejemplo n.º 6
0
    def parse_file(self, rows):
        print "Ingesting Competitions..."
        for keys in rows:
            remote_id = self.column_int("ID", **keys)
            name = self.column_unicode("Name", **keys)
            level = self.column_int("Level", **keys)
            country_name = self.column_unicode("Country", **keys)
            confederation_name = self.column_unicode("Confederation", **keys)

            if all(var is not None for var in [country_name, confederation_name]):
                print "Cannot insert Competition record: Country and Confederation defined"
                continue
            else:
                if country_name is not None:
                    country_id = self.get_id(Countries, name=country_name)
                    comp_dict = dict(name=name, level=level, country_id=country_id)
                    if country_id is not None and not self.record_exists(DomesticCompetitions, **comp_dict):
                        comp_record = DomesticCompetitions(**comp_dict)
                    else:
                        print "Cannot insert Competition record: Country not found or Record exists"
                        continue
                elif confederation_name is not None:
                    try:
                        confederation = ConfederationType.from_string(confederation_name)
                        comp_dict = dict(name=name, level=level, confederation=confederation)
                        if not self.record_exists(InternationalCompetitions, **comp_dict):
                            comp_record = InternationalCompetitions(**comp_dict)
                    except ValueError:
                        print "Cannot insert Competition record: Confederation not found or Record exists"
                        continue
                else:
                    print "Cannot insert Competition record: Neither Country nor Confederation defined"
                    continue
                self.session.add(comp_record)
                self.session.commit()
                self.session.add(CompetitionMap(id=comp_record.id, remote_id=remote_id,
                                                supplier_id=self.supplier_id))
        self.session.commit()
        print "Competition Ingestion complete."