Ejemplo n.º 1
0
    def get_instance():
        logger.info('get_instance() database_instance: {0}'.format(
            Database.database_instance))

        if Database.database_instance is None:
            config_base = config.get('database')
            Database.database_instance = Database(config_base)
            Database.database_instance.create()
        return Database.database_instance
Ejemplo n.º 2
0
                    "min": load[7],
                    "total": load[5] * loadfator
                },
                "voltage": {
                    "avg": load[8],
                    "max": load[9],
                    "min": load[10]
                }
            }
        }


if __name__ == "__main__":
    database = Database.get_instance()

    port = config.get('usb')[0]
    tracer_service = TracerService(serialclient=None, port=port)
    tracer_service.sync_rtc()
    print tracer_service.read_value('Battery Capacity')
#    tracer_service.write_value('Battery Capacity', 60)
#    print tracer_service.read_value('Battery Capacity')

#    chargeEquipmentService = ChargeEquipmentService(tracer_service=tracer_service, database=database)
#    chargeEquipmentService.database.create()
#    chargeEquipList = chargeEquipmentService.find_by_model('Tracer4210A')
#    chargeEquip = chargeEquipList[0]

#    samplingService = SampleService(tracer_service=tracer_service, database=database)
#    print samplingService.get_sample()
#    samplingService.register_statistical(chargeEquip)
#    samplingService.register(chargeEquip)
Ejemplo n.º 3
0
def get_instance_tracer(charge_port):
    return TracerService(serialclient=None, port=charge_port)


def get_instance_equip(tracer_client):
    return ChargeEquipmentService(tracer_service=tracer_client, database=None)


def get_instance_sample(tracer_client):
    return SampleService(tracer_service=tracer_client, database=None)


logger.info('loading usb...')

usb_port_list = config.get('usb')
usb_port = usb_port_list[0]

logger.debug('usb_port_list: ', usb_port_list)
logger.debug('usb_port: ', usb_port)


@app.route("/device", methods=['GET'])
def device():
    logger.info('device()')

    charge_port = request.headers.get('charge_port', usb_port)
    tracer_service = get_instance_tracer(charge_port)
    charge_equipment_service = get_instance_equip(tracer_service)

    device_info = charge_equipment_service.device_info()
Ejemplo n.º 4
0
import time
from env import config

from service.chargeEquipmentService import ChargeEquipmentService
from service.sampleService import SampleService
from service.tracerService import TracerService

from entity.database import Database

database = Database.get_instance()

usb_list = config.get('usb')

for usb in usb_list:
    print usb
    trancer_serv = TracerService(serialclient=None, port=usb)
    equipment_serv = ChargeEquipmentService(tracer_service=trancer_serv, database=database)
    equipment_list = equipment_serv.find_by_port(usb)

    chargeEquip = equipment_list[0]

    samplingService = SampleService(tracer_service=trancer_serv, database=database)
    samplingService.register(chargeEquip)

# delay = 1
# for i in range(0, 10, delay):
#     print i
#     for usb in usb_list:
#         print usb
#         trancer_serv = TracerService(serialclient=None, port=usb)
#         equipment_serv = ChargeEquipmentService(tracer_service=trancer_serv, database=database)
Ejemplo n.º 5
0
from env import config
from app.app import app

serve_config = config.get('serve')

app.run(host=serve_config.get('ip'),
        port=serve_config.get('port'),
        debug=serve_config.get('debug'))
Ejemplo n.º 6
0
from service.chargeEquipmentService import ChargeEquipmentService
from service.sampleService import SampleService

from flask import Flask, jsonify, request

logger = log(__name__)
logger.info('Tenergy Serve')

for key, value in config.iteritems():
    logger.debug('config.json: {0}, {1}'.format(key, value))

database = Database.get_instance()

app = Flask(__name__)

usb_port = config.get('usb')[0]


def get_instance_tracer(charge_port):
    return TracerService(serialclient=None, port=charge_port)


def get_instance_equip(tracer_client):
    return ChargeEquipmentService(tracer_service=tracer_client,
                                  database=database)


def get_instance_sample(tracer_client):
    return SampleService(tracer_service=tracer_client, database=database)

Ejemplo n.º 7
0
import time
import jwt
import datetime
import hashlib

from env import log, config

from entity.database import Database

from entity.user import User

from sqlalchemy import func, desc

from flask_login import UserMixin

serve = config.get('serve')
secret_key = serve['secret_key']

logger = log(__name__)


class UserSession(UserMixin):
    def __init__(self, first_name, last_name, session_token):
        self.first_name = first_name
        self.last_name = last_name
        self.session_token = session_token

    def get_id(self):
        return unicode(self.session_token)

    def __str__(self):