Example #1
0
    def create_connection(self):
        """
        Override the create_connection from the DbConnectionWrapper
        class which get's called in it's initializer
        """
        from cassandra.cluster import Cluster
        from cassandra.query import dict_factory

        session = Cluster(self.nodes).connect()

        # Don't return paged results
        session.default_fetch_size = self.default_fetch_size

        # Return in dictionary format for easy parsing to DataFrame
        session.row_factory = dict_factory

        return session
Example #2
0
    def create_connection(self):
        """
        Override the create_connection from the DbConnectionWrapper
        class which get's called in it's initializer
        """
        from cassandra.cluster import Cluster
        from cassandra.query import dict_factory

        session = Cluster(self.nodes).connect()
        
        # Don't return paged results
        session.default_fetch_size = self.default_fetch_size
        
        # Return in dictionary format for easy parsing to DataFrame
        session.row_factory = dict_factory

        return session
Example #3
0
                         SELECT
                         id,
                         group,
                         cycle,
                         double_sum(metric) AS energy
                         FROM battery_metrics.discharge_energy
                         WHERE group=\'{}\' AND cycle={};
                         """.format(group_name, cycle_number))

    # Calculates deep dive metrics (mean, std dev, and percent deviation)
    mean = df["energy"].mean()
    stdev = df["energy"].std()
    df["percent deviation"] = (df["energy"] - mean) * 100.0 / (2.0 * stdev)
    df.sort_values(by="percent deviation", ascending=False)

    for n in ("energy", "percent deviation"):
        df[n] = df[n].map(lambda x: round(x, 1))

    return df.to_dict("records")


## MAIN MODULE
if __name__ == "__main__":
    # Sets formatting for retrieved database query
    db_session.row_factory = create_dataframe
    db_session.default_fetch_size = None

    # Starts Flask/Dash app
    app.run_server(debug=False, host="0.0.0.0", port=80)

## END OF FILE