def process(self, items_block):
        """Process a DataFrame to compute Onion.

        :param items_block: items to be processed. Expects to find a pandas DataFrame.
        """

        logger.info(self.__log_prefix + " Authors to process: " +
                    str(len(items_block)))

        onion_enrich = Onion(items_block)
        df_onion = onion_enrich.enrich(
            member_column=ESOnionConnector.AUTHOR_UUID,
            events_column=ESOnionConnector.CONTRIBUTIONS)

        # Get and store Quarter as String
        df_onion['quarter'] = df_onion[ESOnionConnector.TIMEFRAME].map(
            lambda x: str(pandas.Period(x, 'Q')))

        # Add metadata: enriched on timestamp
        df_onion['metadata__enriched_on'] = datetime.utcnow().isoformat()
        df_onion['data_source'] = self.data_source
        df_onion['grimoire_creation_date'] = df_onion[
            ESOnionConnector.TIMEFRAME]

        logger.info(self.__log_prefix + " Final new events: " +
                    str(len(df_onion)))

        return self.ProcessResults(processed=len(df_onion), out_items=df_onion)
Beispiel #2
0
    def test_Onion(self):
        """Test several cases for the Onion analysis
        """

        members_df = pandas.read_csv(os.path.join(self.__enrich_dir,
                                                  "onion.csv"))
        onion = Onion(members_df)
        enriched_df = onion.enrich("author", "events")

        self.assertFalse(enriched_df.empty)

        self.assertTrue(len(enriched_df), 7)
        self.assertTrue(len(enriched_df[enriched_df["onion_role"]=="core"]), 1)
        self.assertTrue(len(enriched_df[enriched_df["onion_role"]=="regular"]), 3)
        self.assertTrue(len(enriched_df[enriched_df["onion_role"]=="casual"]), 4)
Beispiel #3
0
    def test_Onion(self):
        """Test several cases for the Onion analysis
        """

        members_df = pandas.read_csv(
            os.path.join(self.__enrich_dir, "onion.csv"))
        onion = Onion(members_df)
        enriched_df = onion.enrich("author", "events")

        self.assertFalse(enriched_df.empty)

        self.assertTrue(len(enriched_df), 7)
        self.assertTrue(len(enriched_df[enriched_df["onion_role"] == "core"]),
                        1)
        self.assertTrue(
            len(enriched_df[enriched_df["onion_role"] == "regular"]), 3)
        self.assertTrue(
            len(enriched_df[enriched_df["onion_role"] == "casual"]), 4)