<commit_before>import logging
import json

from impactstoryanalytics.widgets.widget import Widget
from impactstoryanalytics.widgets.widget_api_helpers import Keenio
import impactstoryanalytics.widgets.widget_api_helpers as helpers

logger = logging.getLogger("impactstoryanalytics.widgets.api_key_item_creates")


class Api_key_item_creates(Widget):

    def get_data(self):
        queries = {
            "request": {
                "project": "production",
                "analysis": "count",
                "params": {}
            }
        }
        shared_params = {
            "event_collection": "Created item because of registration",
            "group_by": "api_key",
            "timeframe": "this_30_days", # change to last_30_days after we have some data
            "interval": "daily"
        }

        keenio = Keenio(queries, shared_params)
        raw_data = keenio.get_raw_data()

        ungrouped = Keenio.ungroup(raw_data, "request", "api_key")
        for mydict in ungrouped:
            try:
                mydict["EMPTY_STRING"] = mydict[""]
                del mydict[""]
            except KeyError:
                pass

        return ungrouped
<commit_msg>api_key_item_creates now displays 0s instead of nulls<commit_after>import logging
import json

from impactstoryanalytics.widgets.widget import Widget
from impactstoryanalytics.widgets.widget_api_helpers import Keenio
import impactstoryanalytics.widgets.widget_api_helpers as helpers

logger = logging.getLogger("impactstoryanalytics.widgets.api_key_item_creates")


class Api_key_item_creates(Widget):

    def get_data(self):
        queries = {
            "request": {
                "project": "production",
                "analysis": "count",
                "params": {}
            }
        }
        shared_params = {
            "event_collection": "Created item because of registration",
            "group_by": "api_key",
            "timeframe": "this_30_days", # change to last_30_days after we have some data
            "interval": "daily"
        }

        keenio = Keenio(queries, shared_params)
        raw_data = keenio.get_raw_data()

        ungrouped = Keenio.ungroup(raw_data, "request", "api_key")

        all_api_keys = []
        for one_day_dict in ungrouped:
            all_api_keys += one_day_dict.keys()
        all_api_keys_set = set(all_api_keys)

        for one_day_dict in ungrouped:
            for api_key in all_api_keys_set:
                try:
                    if not one_day_dict[api_key]:
                        one_day_dict[api_key] = 0
                except KeyError:
                    pass
            try:
                one_day_dict["EMPTY_STRING"] = one_day_dict[""]
                del one_day_dict[""]
            except KeyError:
                pass

        return ungrouped

{'fraction_non_alphanumeric': 0.08421423537702608, 'fraction_numerical': 0.0035236081747709656, 'mean_word_length': 2.0494092373791624, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7553218', 'n_tokens_mistral': 837, 'n_tokens_neox': 803, 'n_words': 174}