<commit_before># -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
# @author: <NAME>
#
import json

from oslo.db.sqlalchemy import models
import sqlalchemy
from sqlalchemy.ext import declarative

Base = declarative.declarative_base()


class RatedDataFrame(Base, models.ModelBase):
    """A rated data frame.

    """
    __table_args__ = {'mysql_charset': "utf8",
                      'mysql_engine': "InnoDB"}
    __tablename__ = 'rated_data_frames'

    id = sqlalchemy.Column(sqlalchemy.Integer,
                           primary_key=True)
    begin = sqlalchemy.Column(sqlalchemy.DateTime,
                              nullable=False)
    end = sqlalchemy.Column(sqlalchemy.DateTime,
                            nullable=False)
    unit = sqlalchemy.Column(sqlalchemy.String(255),
                             nullable=False)
    qty = sqlalchemy.Column(sqlalchemy.Numeric(),
                            nullable=False)
    res_type = sqlalchemy.Column(sqlalchemy.String(255),
                                 nullable=False)
    rate = sqlalchemy.Column(sqlalchemy.Float(),
                             nullable=False)
    desc = sqlalchemy.Column(sqlalchemy.Text(),
                             nullable=False)

    def to_cloudkitty(self):
        rating_dict = {}
        rating_dict['price'] = self.rate
        vol_dict = {}
        vol_dict['qty'] = self.qty
        vol_dict['unit'] = self.unit
        res_dict = {}
        res_dict['billing'] = rating_dict
        res_dict['desc'] = json.loads(self.desc)
        res_dict['vol'] = vol_dict
        ck_dict = {}
        ck_dict[self.res_type] = [res_dict]
        return ck_dict<commit_msg>Fixed output format for sqlalchemy storage backend<commit_after># -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
# @author: <NAME>
#
import json

from oslo.db.sqlalchemy import models
import sqlalchemy
from sqlalchemy.ext import declarative

Base = declarative.declarative_base()


class RatedDataFrame(Base, models.ModelBase):
    """A rated data frame.

    """
    __table_args__ = {'mysql_charset': "utf8",
                      'mysql_engine': "InnoDB"}
    __tablename__ = 'rated_data_frames'

    id = sqlalchemy.Column(sqlalchemy.Integer,
                           primary_key=True)
    begin = sqlalchemy.Column(sqlalchemy.DateTime,
                              nullable=False)
    end = sqlalchemy.Column(sqlalchemy.DateTime,
                            nullable=False)
    unit = sqlalchemy.Column(sqlalchemy.String(255),
                             nullable=False)
    qty = sqlalchemy.Column(sqlalchemy.Numeric(),
                            nullable=False)
    res_type = sqlalchemy.Column(sqlalchemy.String(255),
                                 nullable=False)
    rate = sqlalchemy.Column(sqlalchemy.Float(),
                             nullable=False)
    desc = sqlalchemy.Column(sqlalchemy.Text(),
                             nullable=False)

    def to_cloudkitty(self):
        period_dict = {}
        period_dict['begin'] = self.begin.isoformat()
        period_dict['end'] = self.end.isoformat()
        rating_dict = {}
        rating_dict['price'] = self.rate
        vol_dict = {}
        vol_dict['qty'] = self.qty
        vol_dict['unit'] = self.unit
        res_dict = {}
        res_dict['billing'] = rating_dict
        res_dict['desc'] = json.loads(self.desc)
        res_dict['vol'] = vol_dict
        usage_dict = {}
        usage_dict[self.res_type] = [res_dict]
        ck_dict = {}
        ck_dict['period'] = period_dict
        ck_dict['usage'] = usage_dict
        return ck_dict
{'fraction_non_alphanumeric': 0.09816726353486413, 'fraction_numerical': 0.0067410996418790815, 'mean_word_length': 2.249828884325804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1996416', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1356, 'n_words': 337}