def __make_stats_item()

in modular_api/services/usage_service.py [0:0]


    def __make_stats_item(self, mount_point, group, command, meta, status,
                          event_type, product, job_id):
        last = self._get_last()
        if last:
            self.last_rec_ts = last.timestamp
            self.last_rec_date = last.date

        utc_time_now = datetime.now(timezone.utc)
        ts = int(utc_time_now.timestamp()) * 1000
        date = utc_time_now.strftime(DATE_FORMAT)
        prev_item_id = None
        stats_doc = {
            DATE: date,
            M_POINT: mount_point,
            GROUP: group,
            COMMAND: command,
            META: meta,
            STATUS: status,
            EVENT_TYPE: event_type,
            PRODUCT: product
        }
        if event_type != EVENT_TYPE_API:
            for key in [GROUP, COMMAND]:
                stats_doc.pop(key)
            stats_doc.update({JOB_ID: job_id})
        hex_hash = hashlib.md5(
            json.dumps(stats_doc, sort_keys=True).encode('utf-8')).hexdigest()
        current_ts = ts + (int(hex_hash, 16) % 1000)
        if current_ts == self.last_rec_ts:
            current_ts += 2
        stats_doc.update(timestamp=current_ts)
        if (not self.last_rec_date or
                (self.__start_month_ts(date) != self.__start_month_ts(
                    self.last_rec_date))):
            item_id = (self.__start_month_ts(date) + current_ts +
                       self.__start_month_ts(date, next_month=True))
        else:
            item_id = (self.last_rec_ts + current_ts +
                       self.__start_month_ts(date, next_month=True))
            prev_item_id = self.__make_previous_item_id(date=date,
                                                        timestamp=current_ts)
        hex_hash = hashlib.md5(
            json.dumps(item_id, sort_keys=True).encode('utf-8')).hexdigest()
        stats_doc.update(id=hex_hash)
        return stats_doc, current_ts, date, prev_item_id