コード例 #1
0
 def _parse_url_path(self, row):
     """
     Perform data cleaning and type conversion on a URL path file entry.
     """
     clean_row = row.copy()
     # Convert the special flag from string to boolean
     clean_row['special'] = row['special'].lower() == 'true'
     # Add an election_slug entry if it doesn't already exist 
     if 'election_slug' not in clean_row:
         clean_row['election_slug'] = election_slug(self.state,
             clean_row['date'], clean_row['race_type'], clean_row['special']) 
     return clean_row
コード例 #2
0
ファイル: datasource.py プロジェクト: poochmonster/core
 def _parse_url_path(self, row):
     """
     Perform data cleaning and type conversion on a URL path file entry.
     """
     clean_row = row.copy()
     # Convert the special flag from string to boolean
     clean_row['special'] = row['special'].lower() == 'true'
     # Add an election_slug entry if it doesn't already exist
     if 'election_slug' not in clean_row:
         clean_row['election_slug'] = election_slug(self.state,
                                                    clean_row['date'],
                                                    clean_row['race_type'],
                                                    clean_row['special'])
     return clean_row
コード例 #3
0
    def _election_slug(self, election):
        """
        Generate a slug for an election.

        Arguments:

        * election - Dictionary of election attributes as returned by the
                     metadata API.

        """
        # Delete the 'state' key in the election attrs, because its a
        # dict with multiple values we don't care about and we want
        # to just pass the value of self.state to election_slug.  
        # We can probably delete the key from argument without consequence, 
        # but to be safe and avoid side effects,copy the argument first.
        election_attrs = election.copy()
        try:
            del election_attrs['state']
        except  KeyError:
            pass
        return election_slug(self.state, **election_attrs)
コード例 #4
0
ファイル: datasource.py プロジェクト: poochmonster/core
    def _election_slug(self, election):
        """
        Generate a slug for an election.

        Arguments:

        * election - Dictionary of election attributes as returned by the
                     metadata API.

        """
        # Delete the 'state' key in the election attrs, because its a
        # dict with multiple values we don't care about and we want
        # to just pass the value of self.state to election_slug.
        # We can probably delete the key from argument without consequence,
        # but to be safe and avoid side effects,copy the argument first.
        election_attrs = election.copy()
        try:
            del election_attrs['state']
        except KeyError:
            pass
        return election_slug(self.state, **election_attrs)
コード例 #5
0
    def _parse_url_path(self, row):
        """
        Perform data cleaning and type conversion on a URL path file entry.

        Args:
            row: Dictionary representing a single row of data in the CSV file.

        Returns:
            A dictionary with cleaned and transformed values.  The
            ``special`` value is converted from a string to a boolean
            and an ``election_slug`` value is added if not already
            present.

        """
        clean_row = row.copy()
        # Convert the special flag from string to boolean
        clean_row['special'] = row['special'].lower() == 'true'
        # Add an election_slug entry if it doesn't already exist
        if 'election_slug' not in clean_row:
            clean_row['election_slug'] = election_slug(self.state,
                clean_row['date'], clean_row['race_type'], clean_row['special'])
        return clean_row
コード例 #6
0
ファイル: test_lib.py プロジェクト: Sambesia/oe-core
    def test_election_slug(self):
        elec_attrs = {
            'md-2012-11-06-general': {
                'state': 'md',
                'start_date': '2012-11-06',
                'special': False,
                'race_type': 'general',
            },
            'md-2008-06-17-special-general': {
                'state': 'md',
                'start_date': '2008-06-17',
                'special': True,
                'race_type': 'general',
            },
            'ar-2011-05-10-special-primary-runoff': {
                'state': 'ar',
                'start_date': '2011-05-10',
                'special': True,
                'race_type': 'primary-runoff',
            },
        }

        for slug, attrs in elec_attrs.items():
            self.assertEqual(election_slug(**attrs), slug)
コード例 #7
0
    def test_election_slug(self):
        elec_attrs = {
          'md-2012-11-06-general': {
              'state': 'md',
              'start_date': '2012-11-06',
              'special': False,
              'race_type': 'general',
          },
          'md-2008-06-17-special-general': {
              'state': 'md',
              'start_date': '2008-06-17',
              'special': True,
              'race_type': 'general',
          },
          'ar-2011-05-10-special-primary-runoff': {
              'state': 'ar',
              'start_date': '2011-05-10',
              'special': True,
              'race_type': 'primary-runoff',
          },
        }

        for slug, attrs in list(elec_attrs.items()):
            self.assertEqual(election_slug(**attrs), slug)
コード例 #8
0
    def _election_slug(self, election):
        """
        Generate a slug for an election.

        Args:
            election: Dictionary of election attributes as returned by the
                 metadata API.

        Returns:
            A string containing a unique identifier for an election.  For
            example, "ar-2012-05-22-primary".

        """
        # Delete the 'state' key in the election attrs, because its a
        # dict with multiple values we don't care about and we want
        # to just pass the value of self.state to election_slug.
        # We can probably delete the key from argument without consequence,
        # but to be safe and avoid side effects,copy the argument first.
        #        try:
        #            del election_attrs['state']
        #        except  KeyError:
        #            pass
        return election_slug(self.state, election['start_date'],
                             election['race_type'], election['special'])