# Path: app/models.py
# class Respondent(db.Model):
# class Campaign(db.Model):
# class Audience(db.Model):
# class RandomBias(db.Model):
# class PossibleAbuses(db.Model):
# class BlockedClients(db.Model):
# class CallStatistics(db.Model):
# class Role(db.Model, RoleMixin):
# class User(db.Model, UserMixin):
#     def __repr__(self):


from app.models import db, CallStatistics, Campaign
from datetime import datetime


def log_call(call_duration, id_campaign):
    """
    log call statistics and update call minutes on campaign object
    :param call_duration: duration on the call in seconds
    :param id_campaign: id of the campaign
    """
    call = CallStatistics(time=datetime.now(),
                          duration=int(call_duration),
                          campaign=int(id_campaign))
    db.session.add(call)
    db.session.commit()


# Path: app/models.py
# class Respondent(db.Model):
# class Campaign(db.Model):
# class Audience(db.Model):
# class RandomBias(db.Model):
# class PossibleAbuses(db.Model):
# class BlockedClients(db.Model):
# class CallStatistics(db.Model):
# class Role(db.Model, RoleMixin):
# class User(db.Model, UserMixin):
#     def __repr__(self):


# Path: app/statistics/calls.py
from app.models import db, CallStatistics, Campaign
from datetime import datetime



def log_call(call_duration, id_campaign):
    """
    log call statistics and update call minutes on campaign object
    :param call_duration: duration on the call in seconds
    :param id_campaign: id of the campaign
    """
    call = CallStatistics(time=datetime.now(),
                          duration=int(call_duration),
                          campaign=int(id_campaign))
    db.session.add(call)
    db.session.commit()


    calls = CallStatistics().query.filter_by(campaign=int(id_campaign)).all()