コード例 #1
0
ファイル: TaskFactory.py プロジェクト: x100up/analystics
def createTaskFromRequestArguments(arguments):
    appname, = arguments['appname']
    interval, = arguments['group_interval']
    task = Task(appname = appname, interval = interval)
    indexes = arguments['indexes']
    userUniques = []
    if arguments.has_key('userUnique'):
        userUniques = arguments['userUnique']

    for index in indexes:
        if not arguments.has_key('key_' + index):
            continue

        eventCode, = arguments['key_' + index]
        if not eventCode:
            continue

        start = datetime.strptime(repMonth(arguments['start_'+ index][0]), "%d %m %Y %H:%M")
        end = datetime.strptime(repMonth(arguments['end_'+ index][0]), "%d %m %Y %H:%M")

        taskItem = TaskItem(key = eventCode, start = start, end = end, index = index)
        if index in userUniques:
            taskItem.userUnique = True
        # разбираем тег для ключа
        tagNames = []
        tag_name = 'tag_' + index + '_name'
        if arguments.has_key(tag_name):
            tagNames = arguments[tag_name]

        for tagName in tagNames:
            # значения тега
            values = None
            val_index = 'tag_' + index + '_' + tagName
            if arguments.has_key(val_index):
                # convert to unicode
                values = [val.decode('utf-8') for val in arguments[val_index]]

            if not values is None:
                taskItem.addCondition(eventCode, tagName, values)
            # операции с тегом
            op_index = 'tag_' + index + '_' + tagName + '_ops'
            if arguments.has_key(op_index):
                ops = arguments[op_index][0]
                if not ops is None:
                    taskItem.setTagOperations(tagName, ops.split('/'))

        task.addTaskItem(taskItem)

    return  task
コード例 #2
0
    def getTSValues(self, val):
        start = False
        end = False
        dt1 = repMonth(val, decode=False)
        components1 = dt1.split(' ')

        if len(components1) == 2:
            year = int(components1[1])
            month = int(components1[0])
        else:
            year = int(components1[2])
            month = int(components1[1])

        if len(components1) >= 3:
            startDay = endDay = int(components1[0])
        else:
            startDay = 1
            endDay = calendar.monthrange(year, month)[1]

        if len(components1) < 4:
            start = datetime(year, month, startDay, 0, 0, 0)
            end = datetime(year, month, endDay, 23, 59, 59)
        elif len(components1) == 4:
            _time = components1[3]
            _time = _time.split(':')
            hour = int(_time[0])
            minutes = 0
            hasMinutes = len(_time) > 1
            if hasMinutes:
                minutes = int(_time[1])

            start = datetime(year, month, startDay, hour, minute = minutes, second=0)
            if not hasMinutes:
                end = datetime(year, month, endDay, hour, minute = minutes, second=59)

        return start, end