Example #1
0
def EgoSortDictArray(array, user):
    userArray = []
    otherArray = []

    for i in range(0, len(array)):
        if (String.Compare(array[i]["UserName"], user, True) == 0):
            userArray.append(array[i])
        else:
            otherArray.append(array[i])

    for i in range(0, len(otherArray)):
        userArray.append(otherArray[i])

    return userArray
Example #2
0
def merge(left, right, key, order):
    # init return list
    ret = []

    # init position in left and right lists
    leftPos = 0
    rightPos = 0

    # get the length of the two lists
    lenLeft = len(left)
    lenRight = len(right)

    # merge the lists
    if (order == None or order == "0"):
        while (leftPos < lenLeft and rightPos < lenRight):
            if (String.Compare(key, "SubmitDateTime", True) != 0):
                # Normal String Compare
                if (left[leftPos] == None):
                    leftPos += 1
                elif (right[rightPos] == None):
                    rightPos += 1
                elif (String.Compare(left[leftPos][key], right[rightPos][key],
                                     True) <= 0):
                    ret.append(left[leftPos])
                    leftPos += 1
                else:
                    ret.append(right[rightPos])
                    rightPos += 1
            else:
                # Compare Dates
                if (left[leftPos] == None):
                    leftPos += 1
                elif (right[rightPos] == None):
                    rightPos += 1
                else:
                    try:
                        if (DateTime.Compare(
                                DateTime.Parse(left[leftPos][key]),
                                DateTime.Parse(right[rightPos][key])) >= 0):
                            ret.append(left[leftPos])
                            leftPos += 1
                        else:
                            ret.append(right[rightPos])
                            rightPos += 1
                    except:
                        leftPos += 1
    else:
        while (leftPos < lenLeft and rightPos < lenRight):
            if (String.Compare(key, "SubmitDateTime", True) != 0):
                # Normal String Compare
                if (left[leftPos] == None):
                    leftPos += 1
                elif (right[rightPos] == None):
                    rightPos += 1
                elif (String.Compare(left[leftPos][key], right[rightPos][key],
                                     True) >= 0):
                    ret.append(left[leftPos])
                    leftPos += 1
                else:
                    ret.append(right[rightPos])
                    rightPos += 1
            else:
                # Compare Dates
                if (left[leftPos] == None):
                    leftPos += 1
                elif (right[rightPos] == None):
                    rightPos += 1
                else:
                    try:
                        if (DateTime.Compare(
                                DateTime.Parse(left[leftPos][key]),
                                DateTime.Parse(right[rightPos][key])) <= 0):
                            ret.append(left[leftPos])
                            leftPos += 1
                        else:
                            ret.append(right[rightPos])
                            rightPos += 1
                    except:
                        leftPos += 1

    # extend ret with the remaining list
    if (leftPos < lenLeft):
        while (leftPos < lenLeft):
            if (left[leftPos] == None):
                leftPos += 1
            else:
                ret.append(left[leftPos])
                leftPos += 1
    else:
        while (rightPos < lenRight):
            if (right[rightPos] == None):
                rightPos += 1
            else:
                ret.append(right[rightPos])
                rightPos += 1

    return ret