コード例 #1
0
ファイル: diff.py プロジェクト: Betriebsrat/ecm
def get_dates(request):

    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    divisions = extract_divisions(request)

    since_weeks = int(request.GET.get('since_weeks', '8'))
    to_weeks = int(request.GET.get('to_weeks', '0'))

    oldest_date = timezone.now() - timedelta(weeks=since_weeks)
    newest_date = timezone.now() - timedelta(weeks=to_weeks)

    query = AssetDiff.objects.all()
    query = query.filter(date__gte=oldest_date)
    query = query.filter(date__lte=newest_date)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)
    if divisions is not None:
        query = query.filter(hangarID__in=divisions)

    dates = []
    for date in query.values_list('date', flat=True).distinct().order_by('-date'):
        dates.append({
            'value' : datetime.strftime(date, DATE_PATTERN),
            'show' : print_time_min(date),
        })

    return HttpResponse(json.dumps(dates))
コード例 #2
0
ファイル: diff.py プロジェクト: vanderheyde/ecm
def get_systems_data(request, date_str):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)
    # TODO: fix this sql into an object
    sql = 'SELECT "solarSystemID", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE date >= %s AND date < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "solarSystemID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [date, next_date])
    else:
        cursor.execute(sql, [date, next_date] + list(divisions))

    jstree_data = []
    for solarSystemID, items, volume in cursor:
        try:
            system = CelestialObject.objects.get(itemID=solarSystemID)
        except CelestialObject.DoesNotExist:
            system = CelestialObject(itemID=solarSystemID,
                                     itemName=str(solarSystemID),
                                     security=0)
        if system.security > 0.5:
            color = 'hisec'
        elif system.security > 0:
            color = 'lowsec'
        else:
            color = 'nullsec'
        jstree_data.append({
            'data':
            HTML_ITEM_SPAN %
            (system.itemName, items, pluralize(items), volume),
            'attr': {
                'id': '%d_' % solarSystemID,
                'rel': 'system',
                'sort_key': system.itemName.lower(),
                'class': 'system-%s-row' % color
            },
            'state':
            'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #3
0
ファイル: diff.py プロジェクト: vanderheyde/ecm
def search_items(request, date_str):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    search_string = request.GET.get('search_string', None)

    query = AssetDiff.objects.filter(
        eve_type__typeName__icontains=search_string)
    query = query.filter(date__range=(date, next_date))

    if divisions is not None:
        query = query.filter(hangarID__in=divisions)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)

    json_data = []

    for item in query:
        nodeid = '#%d_' % item.solarSystemID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.stationID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.hangarID
        json_data.append(nodeid)

    return HttpResponse(json.dumps(json_data))
コード例 #4
0
ファイル: diff.py プロジェクト: vanderheyde/ecm
def get_dates(request):

    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    divisions = extract_divisions(request)

    since_weeks = int(request.GET.get('since_weeks', '8'))
    to_weeks = int(request.GET.get('to_weeks', '0'))

    oldest_date = timezone.now() - timedelta(weeks=since_weeks)
    newest_date = timezone.now() - timedelta(weeks=to_weeks)

    query = AssetDiff.objects.all()
    query = query.filter(date__gte=oldest_date)
    query = query.filter(date__lte=newest_date)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)
    if divisions is not None:
        query = query.filter(hangarID__in=divisions)

    dates = []
    for date in query.values_list('date',
                                  flat=True).distinct().order_by('-date'):
        dates.append({
            'value': datetime.strftime(date, DATE_PATTERN),
            'show': print_time_min(date),
        })

    return HttpResponse(json.dumps(dates))
コード例 #5
0
ファイル: diff.py プロジェクト: Betriebsrat/ecm
def search_items(request, date_str):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    search_string = request.GET.get('search_string', None)

    query = AssetDiff.objects.filter(eve_type__typeName__icontains=search_string)
    query = query.filter(date__range=(date, next_date))

    if divisions is not None:
        query = query.filter(hangarID__in=divisions)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)


    json_data = []

    for item in query:
        nodeid = '#%d_' % item.solarSystemID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.stationID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.hangarID
        json_data.append(nodeid)

    return HttpResponse(json.dumps(json_data))
コード例 #6
0
ファイル: diff.py プロジェクト: vanderheyde/ecm
def get_stations_data(request, date_str, solarSystemID):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    solarSystemID = int(solarSystemID)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)

    sql = 'SELECT "stationID", MAX("flag") as "flag", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE "solarSystemID"=%s AND "date" >= %s AND "date" < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "stationID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, date, next_date])
    else:
        cursor.execute(sql, [solarSystemID, date, next_date] + list(divisions))

    jstree_data = []
    for stationID, flag, items, volume in cursor:
        if stationID < constants.MAX_STATION_ID:
            # it's a real station
            try:
                name = CelestialObject.objects.get(itemID=stationID).itemName
            except CelestialObject.DoesNotExist:
                name = str(stationID)
            icon = 'station'
        else:
            # it is an inspace anchorable array
            name = Type.objects.get(typeID=flag).typeName
            icon = 'array'

        jstree_data.append({
            'data':
            HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr': {
                'id': '%d_%d_' % (solarSystemID, stationID),
                'sort_key': stationID,
                'rel': icon,
                'class': '%s-row' % icon
            },
            'state':
            'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #7
0
def get_hangars_data(request, solarSystemID, closest_obj_id, stationID):
    solarSystemID = int(solarSystemID)
    closest_obj_id = int(closest_obj_id)
    stationID = int(stationID)
    divisions = extract_divisions(request)

    where = []
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "hangarID", COUNT(*) AS "items", SUM("volume") AS "volume" '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s AND "closest_object_id"=%s AND "stationID"=%s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "hangarID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, closest_obj_id, stationID])
    else:
        cursor.execute(sql, [solarSystemID, closest_obj_id, stationID] +
                       list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    HANGAR = Hangar.DEFAULT_NAMES.copy()
    for h in CorpHangar.objects.filter(corp=Corporation.objects.mine()):
        HANGAR[h.hangar_id] = h.name

    jstree_data = []
    for hangarID, items, volume in cursor:

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data':
            HTML_ITEM_SPAN %
            (HANGAR[hangarID], items, pluralize(items), volume),
            'attr': {
                'id':
                '%d_%d_%d_%d_' %
                (solarSystemID, closest_obj_id, stationID, hangarID),
                'sort_key':
                hangarID,
                'rel':
                'hangar',
                'class':
                'hangar-row'
            },
            'state':
            'closed'
        })

    return HttpResponse(json.dumps(jstree_data))
コード例 #8
0
ファイル: normal.py プロジェクト: Betriebsrat/ecm
def get_systems_data(request):

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "solarSystemID", COUNT(*) AS "items", SUM("volume") AS "volume" '\
          'FROM "assets_asset" '
    if where: sql += ' WHERE ' + ' AND '.join(where)
    sql += ' GROUP BY "solarSystemID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql)
    else:
        cursor.execute(sql, divisions)

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for solarSystemID, items, volume in cursor:
        try:
            system = CelestialObject.objects.get(itemID=solarSystemID)
        except CelestialObject.DoesNotExist:
            system = CelestialObject(itemID=solarSystemID, itemName=str(solarSystemID), security=0)
        if system.security > 0.5:
            color = 'hisec'
        elif system.security > 0:
            color = 'lowsec'
        else:
            color = 'nullsec'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data' : HTML_ITEM_SPAN % (system.itemName, items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_' % solarSystemID,
                'rel' : 'system',
                'sort_key' : system.itemName.lower(),
                'class' : 'system-%s-row' % color
            },
            'state' : 'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #9
0
ファイル: normal.py プロジェクト: Betriebsrat/ecm
def get_celestial_objects_data(request, solarSystemID):
    solarSystemID = int(solarSystemID)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "closest_object_id", COUNT(*), SUM("volume") '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s '
    if where:
        sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "closest_object_id";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID])
    else:
        cursor.execute(sql, [solarSystemID] + list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for closest_object_id, items, volume in cursor:

        if closest_object_id != 0:
            try:
                name = CelestialObject.objects.get(itemID=closest_object_id).itemName
            except CelestialObject.DoesNotExist:
                name = str(closest_object_id)
        else:
            name = 'Stations'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data' : HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_%d_' % (solarSystemID, closest_object_id),
                'sort_key' : closest_object_id,
                'rel' : 'celestial',
                'class' : 'celestial-row',
            },
            'state' : 'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #10
0
ファイル: diff.py プロジェクト: Betriebsrat/ecm
def get_stations_data(request, date_str, solarSystemID):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    solarSystemID = int(solarSystemID)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)

    sql = 'SELECT "stationID", MAX("flag") as "flag", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE "solarSystemID"=%s AND "date" >= %s AND "date" < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "stationID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, date, next_date])
    else:
        cursor.execute(sql, [solarSystemID, date, next_date] + list(divisions))

    jstree_data = []
    for stationID, flag, items, volume in cursor:
        if stationID < constants.MAX_STATION_ID:
            # it's a real station
            try:
                name = CelestialObject.objects.get(itemID=stationID).itemName
            except CelestialObject.DoesNotExist:
                name = str(stationID)
            icon = 'station'
        else:
            # it is an inspace anchorable array
            name = Type.objects.get(typeID=flag).typeName
            icon = 'array'

        jstree_data.append({
            'data' : HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_%d_' % (solarSystemID, stationID),
                'sort_key' : stationID,
                'rel' : icon,
                'class' : '%s-row' % icon
            },
            'state' : 'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #11
0
ファイル: diff.py プロジェクト: Betriebsrat/ecm
def get_systems_data(request, date_str):
    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)
    # TODO: fix this sql into an object
    sql = 'SELECT "solarSystemID", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE date >= %s AND date < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "solarSystemID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [date, next_date])
    else:
        cursor.execute(sql, [date, next_date] + list(divisions))

    jstree_data = []
    for solarSystemID, items, volume in cursor:
        try:
            system = CelestialObject.objects.get(itemID=solarSystemID)
        except CelestialObject.DoesNotExist:
            system = CelestialObject(itemID=solarSystemID, itemName=str(solarSystemID), security=0)
        if system.security > 0.5:
            color = 'hisec'
        elif system.security > 0:
            color = 'lowsec'
        else:
            color = 'nullsec'
        jstree_data.append({
            'data' : HTML_ITEM_SPAN % (system.itemName, items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_' % solarSystemID,
                'rel' : 'system',
                'sort_key' : system.itemName.lower(),
                'class' : 'system-%s-row' % color
            },
            'state' : 'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #12
0
ファイル: normal.py プロジェクト: Betriebsrat/ecm
def get_hangars_data(request, solarSystemID, closest_obj_id, stationID):
    solarSystemID = int(solarSystemID)
    closest_obj_id = int(closest_obj_id)
    stationID = int(stationID)
    divisions = extract_divisions(request)

    where = []
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "hangarID", COUNT(*) AS "items", SUM("volume") AS "volume" '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s AND "closest_object_id"=%s AND "stationID"=%s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "hangarID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, closest_obj_id, stationID])
    else:
        cursor.execute(sql, [solarSystemID, closest_obj_id, stationID] + list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    HANGAR = Hangar.DEFAULT_NAMES.copy()
    for h in CorpHangar.objects.filter(corp=Corporation.objects.mine()):
        HANGAR[h.hangar_id] = h.name

    jstree_data = []
    for hangarID, items, volume in cursor:

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data': HTML_ITEM_SPAN % (HANGAR[hangarID], items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_%d_%d_%d_' % (solarSystemID, closest_obj_id, stationID, hangarID),
                'sort_key' : hangarID,
                'rel' : 'hangar',
                'class' : 'hangar-row'
            },
            'state' : 'closed'
        })

    return HttpResponse(json.dumps(jstree_data))
コード例 #13
0
ファイル: diff.py プロジェクト: vanderheyde/ecm
def get_hangars_data(request, date_str, solarSystemID, stationID):

    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    solarSystemID = int(solarSystemID)
    stationID = int(stationID)
    divisions = extract_divisions(request)

    where = []
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)

    sql = 'SELECT "hangarID", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE "solarSystemID"=%s AND "stationID"=%s AND "date" >= %s AND "date" < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "hangarID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, stationID, date, next_date])
    else:
        cursor.execute(sql, [solarSystemID, stationID, date, next_date] +
                       list(divisions))

    HANGAR = Hangar.DEFAULT_NAMES.copy()
    for h in CorpHangar.objects.filter(corp=Corporation.objects.mine()):
        HANGAR[h.hangar_id] = h.name

    jstree_data = []
    for hangarID, items, volume in cursor.fetchall():
        jstree_data.append({
            'data':
            HTML_ITEM_SPAN %
            (HANGAR[hangarID], items, pluralize(items), volume),
            'attr': {
                'id': '%d_%d_%d_' % (solarSystemID, stationID, hangarID),
                'sort_key': hangarID,
                'rel': 'hangar',
                'class': 'hangar-row'
            },
            'state':
            'closed'
        })

    return HttpResponse(json.dumps(jstree_data))
コード例 #14
0
ファイル: diff.py プロジェクト: Betriebsrat/ecm
def get_hangars_data(request, date_str, solarSystemID, stationID):

    date = datetime.strptime(date_str, DATE_PATTERN)
    date = timezone.make_aware(date, timezone.utc)
    next_date = date + timedelta(seconds=1)
    solarSystemID = int(solarSystemID)
    stationID = int(stationID)
    divisions = extract_divisions(request)

    where = []
    if divisions is not None:
        s = ('%s,' * len(divisions))[:-1]
        where.append('"hangarID" IN (%s)' % s)

    sql = 'SELECT "hangarID", COUNT(*) AS "items", SUM("volume") AS "volume" '
    sql += 'FROM "assets_assetdiff" '
    sql += 'WHERE "solarSystemID"=%s AND "stationID"=%s AND "date" >= %s AND "date" < %s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "hangarID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, stationID, date, next_date])
    else:
        cursor.execute(sql, [solarSystemID, stationID, date, next_date] + list(divisions))

    HANGAR = Hangar.DEFAULT_NAMES.copy()
    for h in CorpHangar.objects.filter(corp=Corporation.objects.mine()):
        HANGAR[h.hangar_id] = h.name

    jstree_data = []
    for hangarID, items, volume in cursor.fetchall():
        jstree_data.append({
            'data': HTML_ITEM_SPAN % (HANGAR[hangarID], items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_%d_%d_' % (solarSystemID, stationID, hangarID),
                'sort_key' : hangarID,
                'rel' : 'hangar',
                'class' : 'hangar-row'
            },
            'state' : 'closed'
        })

    return HttpResponse(json.dumps(jstree_data))
コード例 #15
0
def search_items(request):

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    search_string = request.GET.get('search_string', None)

    filter_args = Q(name__icontains=search_string)
    if search_string:
        filter_args |= Q(eve_type__typeName__icontains=search_string)

    query = Asset.objects.filter(filter_args)

    if divisions is not None:
        query = query.filter(hangarID__in=divisions)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)

    json_data = []

    for item in query:
        nodeid = '#%d_' % item.solarSystemID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.closest_object_id
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.stationID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.hangarID
        json_data.append(nodeid)
        if item.container1:
            nodeid = nodeid + '%d_' % item.container1
            json_data.append(nodeid)
            if item.container2:
                nodeid = nodeid + '%d_' % item.container2
                json_data.append(nodeid)

    return HttpResponse(json.dumps(json_data))
コード例 #16
0
ファイル: normal.py プロジェクト: Betriebsrat/ecm
def search_items(request):

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))
    search_string = request.GET.get('search_string', None)

    filter_args = Q(name__icontains=search_string)
    if search_string:
        filter_args |= Q(eve_type__typeName__icontains=search_string)

    query = Asset.objects.filter(filter_args)

    if divisions is not None:
        query = query.filter(hangarID__in=divisions)
    if not show_in_space:
        query = query.filter(stationID__lt=constants.MAX_STATION_ID)
    if not show_in_stations:
        query = query.filter(stationID__gt=constants.MAX_STATION_ID)

    json_data = []

    for item in query:
        nodeid = '#%d_' % item.solarSystemID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.closest_object_id
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.stationID
        json_data.append(nodeid)
        nodeid = nodeid + '%d_' % item.hangarID
        json_data.append(nodeid)
        if item.container1:
            nodeid = nodeid + '%d_' % item.container1
            json_data.append(nodeid)
            if item.container2:
                nodeid = nodeid + '%d_' % item.container2
                json_data.append(nodeid)

    return HttpResponse(json.dumps(json_data))
コード例 #17
0
def get_systems_data(request):

    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "solarSystemID", COUNT(*) AS "items", SUM("volume") AS "volume" '\
          'FROM "assets_asset" '
    if where: sql += ' WHERE ' + ' AND '.join(where)
    sql += ' GROUP BY "solarSystemID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql)
    else:
        cursor.execute(sql, divisions)

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for solarSystemID, items, volume in cursor:
        try:
            system = CelestialObject.objects.get(itemID=solarSystemID)
        except CelestialObject.DoesNotExist:
            system = CelestialObject(itemID=solarSystemID,
                                     itemName=str(solarSystemID),
                                     security=0)
        if system.security > 0.5:
            color = 'hisec'
        elif system.security > 0:
            color = 'lowsec'
        else:
            color = 'nullsec'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data':
            HTML_ITEM_SPAN %
            (system.itemName, items, pluralize(items), volume),
            'attr': {
                'id': '%d_' % solarSystemID,
                'rel': 'system',
                'sort_key': system.itemName.lower(),
                'class': 'system-%s-row' % color
            },
            'state':
            'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #18
0
ファイル: normal.py プロジェクト: Betriebsrat/ecm
def get_stations_data(request, solarSystemID, closest_obj_id):
    solarSystemID = int(solarSystemID)
    closest_obj_id = int(closest_obj_id)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "stationID", MAX("name"), MAX("flag"), COUNT(*), SUM("volume") '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s AND "closest_object_id"=%s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "stationID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor() #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, closest_obj_id])
    else:
        cursor.execute(sql, [solarSystemID, closest_obj_id] + list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for stationID, item_name, flag, items, volume in cursor:
        if stationID < constants.MAX_STATION_ID:
            # it's a real station
            try:
                name = CelestialObject.objects.get(itemID=stationID).itemName
            except CelestialObject.DoesNotExist:
                name = str(stationID)
            icon = 'station'
        else:
            # it is an inspace anchorable array
            type_name = Type.objects.get(typeID=flag).typeName

            name = type_name
            if item_name and type_name != item_name:
                name += ' "%s"' % item_name

            if constants.CONTROL_TOWERS.has_key(flag):
                icon = 'pos'
            else:
                icon = 'array'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data' : HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr' : {
                'id' : '%d_%d_%d_' % (solarSystemID, closest_obj_id, stationID),
                'sort_key' : stationID,
                'rel' : icon,
                'class' : '%s-row' % icon
            },
            'state' : 'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #19
0
def get_celestial_objects_data(request, solarSystemID):
    solarSystemID = int(solarSystemID)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "closest_object_id", COUNT(*), SUM("volume") '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s '
    if where:
        sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "closest_object_id";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID])
    else:
        cursor.execute(sql, [solarSystemID] + list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for closest_object_id, items, volume in cursor:

        if closest_object_id != 0:
            try:
                name = CelestialObject.objects.get(
                    itemID=closest_object_id).itemName
            except CelestialObject.DoesNotExist:
                name = str(closest_object_id)
        else:
            name = 'Stations'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data':
            HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr': {
                'id': '%d_%d_' % (solarSystemID, closest_object_id),
                'sort_key': closest_object_id,
                'rel': 'celestial',
                'class': 'celestial-row',
            },
            'state':
            'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))
コード例 #20
0
def get_stations_data(request, solarSystemID, closest_obj_id):
    solarSystemID = int(solarSystemID)
    closest_obj_id = int(closest_obj_id)
    divisions = extract_divisions(request)
    show_in_space = json.loads(request.GET.get('space', 'true'))
    show_in_stations = json.loads(request.GET.get('stations', 'true'))

    where = []
    if not show_in_space:
        where.append('"stationID" < %d' % constants.MAX_STATION_ID)
    if not show_in_stations:
        where.append('"stationID" > %d' % constants.MAX_STATION_ID)
    if divisions is not None:
        where.append('"hangarID" IN (%s)' % ', '.join(['%s'] * len(divisions)))

    sql = 'SELECT "stationID", MAX("name"), MAX("flag"), COUNT(*), SUM("volume") '\
          'FROM "assets_asset" '\
          'WHERE "solarSystemID"=%s AND "closest_object_id"=%s '
    if where: sql += ' AND ' + ' AND '.join(where)
    sql += ' GROUP BY "stationID";'
    sql = db.fix_mysql_quotes(sql)

    cursor = connection.cursor()  #@UndefinedVariable
    if divisions is None:
        cursor.execute(sql, [solarSystemID, closest_obj_id])
    else:
        cursor.execute(sql, [solarSystemID, closest_obj_id] + list(divisions))

    exact_volumes = Setting.get('assets_show_exact_volumes')

    jstree_data = []
    for stationID, item_name, flag, items, volume in cursor:
        if stationID < constants.MAX_STATION_ID:
            # it's a real station
            try:
                name = CelestialObject.objects.get(itemID=stationID).itemName
            except CelestialObject.DoesNotExist:
                name = str(stationID)
            icon = 'station'
        else:
            # it is an inspace anchorable array
            type_name = Type.objects.get(typeID=flag).typeName

            name = type_name
            if item_name and type_name != item_name:
                name += ' "%s"' % item_name

            if constants.CONTROL_TOWERS.has_key(flag):
                icon = 'pos'
            else:
                icon = 'array'

        if exact_volumes:
            volume = print_float(volume)
        else:
            volume = round_quantity(volume)

        jstree_data.append({
            'data':
            HTML_ITEM_SPAN % (name, items, pluralize(items), volume),
            'attr': {
                'id': '%d_%d_%d_' % (solarSystemID, closest_obj_id, stationID),
                'sort_key': stationID,
                'rel': icon,
                'class': '%s-row' % icon
            },
            'state':
            'closed'
        })
    cursor.close()
    return HttpResponse(json.dumps(jstree_data))