# Path: model/models.py
# def bind_session(connection_string, echo=False):
# class Measure(Base):
# class Settings(Base):
# 
# Path: model/hlr.py
# def bind_session(connection_string, echo=False):
# def user_data_decode(user_data, data_coding_scheme, ud_hdr_ind):
# def create_sms(src_addr, dest_addr, text, charset=None):
# class Subscriber(Base):
# class Sms(Base):


from datetime import datetime
from pyramid.view import view_config
from sqlalchemy import func
from model.models import (
    DBSession,
    Measure,
)
from model.hlr import (
    HLRDBSession,
    Sms,
    Subscriber,
    user_data_decode,
)
import time
import xmlrpclib
import socket
# -*- coding: utf-8 -*-





@view_config(route_name='get_imsi_list', request_method='GET', renderer='json')
def get_imsi_list(request):
    result = []
    messages = []

    query = DBSession.query(
        Measure.id,
        Measure.imsi,
        func.max(Measure.timestamp).label('last')
    ).group_by(Measure.imsi).all()

    for measure in query:
        dtime = datetime.now() - measure.last
        result.append({
            'id': measure.id,
            'imsi': measure.imsi,
            'last_lur': dtime.total_seconds() // 60
        })


    # Calculate message count for each IMSI
    imsi_list = map(lambda item: item['imsi'], result);
    query = HLRDBSession.query(

# Path: model/models.py
# def bind_session(connection_string, echo=False):
# class Measure(Base):
# class Settings(Base):
# 
# Path: model/hlr.py
# def bind_session(connection_string, echo=False):
# def user_data_decode(user_data, data_coding_scheme, ud_hdr_ind):
# def create_sms(src_addr, dest_addr, text, charset=None):
# class Subscriber(Base):
# class Sms(Base):


# Path: web/peoplefinder/views/imsi.py
from datetime import datetime
from pyramid.view import view_config
from sqlalchemy import func
from model.models import (
    DBSession,
    Measure,
)
from model.hlr import (
    HLRDBSession,
    Sms,
    Subscriber,
    user_data_decode,
)
import time
import xmlrpclib
import socket

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





@view_config(route_name='get_imsi_list', request_method='GET', renderer='json')
def get_imsi_list(request):
    result = []
    messages = []

    query = DBSession.query(
        Measure.id,
        Measure.imsi,
        func.max(Measure.timestamp).label('last')
    ).group_by(Measure.imsi).all()

    for measure in query:
        dtime = datetime.now() - measure.last
        result.append({
            'id': measure.id,
            'imsi': measure.imsi,
            'last_lur': dtime.total_seconds() // 60
        })


    # Calculate message count for each IMSI
    imsi_list = map(lambda item: item['imsi'], result);
    query = HLRDBSession.query(

        Subscriber.imsi,