# Path: pytorque/models.py
# class PBSServer(models.Model):
#     time = models.DateTimeField(
#         default=datetime.now)#auto_now_add=True sets datetime with creating object, not with every modifying action
# 
#     name = models.CharField(max_length=100)
#     state = models.CharField(max_length=20)
#     total_jobs = models.IntegerField()
#     running_jobs = models.IntegerField()
#     queued_jobs = models.IntegerField()
#     pbs_version = models.CharField(max_length=10)
# 
# class PBSUserStat(models.Model):
#     time = models.DateTimeField(default=datetime.now, auto_now_add=True)
# 
#     username = models.CharField(default='', max_length=100, blank=True, null=True)
#     jobCount = models.IntegerField(default=0, blank=True, null=True)


from datetime import timedelta, datetime
from chartit import DataPool, Chart
from pytorque.models import PBSServer, PBSUserStat
import time
# -*- coding: utf-8 -*-


class ChartGenerator():
    @staticmethod
    def getJobStatChart(title, currentTime):
        statistics =\
        DataPool(
            series=
            [{'options': {
                'source': PBSServer.objects.order_by('-time')[:20] }, #filter(time__gte=(currentTime - timedelta(hours=+2)))},
              #order_by('time')[9:]
              'terms': [
                  ('time', lambda d: time.mktime(d.timetuple())),
                  'running_jobs',
                  'queued_jobs',
                  'total_jobs']}
            ])

        #Step 2: Create the Chart object
        chart = Chart(
            datasource=statistics,
            series_options=
            [{'options': {
                'type': 'line',
                'stacking': False},
              'terms': {

# Path: pytorque/models.py
# class PBSServer(models.Model):
#     time = models.DateTimeField(
#         default=datetime.now)#auto_now_add=True sets datetime with creating object, not with every modifying action
# 
#     name = models.CharField(max_length=100)
#     state = models.CharField(max_length=20)
#     total_jobs = models.IntegerField()
#     running_jobs = models.IntegerField()
#     queued_jobs = models.IntegerField()
#     pbs_version = models.CharField(max_length=10)
# 
# class PBSUserStat(models.Model):
#     time = models.DateTimeField(default=datetime.now, auto_now_add=True)
# 
#     username = models.CharField(default='', max_length=100, blank=True, null=True)
#     jobCount = models.IntegerField(default=0, blank=True, null=True)


# Path: pytorque/libs/charts.py
from datetime import timedelta, datetime
from chartit import DataPool, Chart
from pytorque.models import PBSServer, PBSUserStat
import time

# -*- coding: utf-8 -*-


class ChartGenerator():
    @staticmethod
    def getJobStatChart(title, currentTime):
        statistics =\
        DataPool(
            series=
            [{'options': {
                'source': PBSServer.objects.order_by('-time')[:20] }, #filter(time__gte=(currentTime - timedelta(hours=+2)))},
              #order_by('time')[9:]
              'terms': [
                  ('time', lambda d: time.mktime(d.timetuple())),
                  'running_jobs',
                  'queued_jobs',
                  'total_jobs']}
            ])

        #Step 2: Create the Chart object
        chart = Chart(
            datasource=statistics,
            series_options=
            [{'options': {
                'type': 'line',
                'stacking': False},
              'terms': {

                  'time': [