Пример #1
0
def ajax_load_matches(request):
    if not request.is_ajax():
        raise Http404

    league_id = request.GET.get('sendValue')

    sql_string = "SELECT MATCH_ID, HOME_TEAM_ID, VISITOR_TEAM_ID FROM sentiosp_drupal6.tf_match WHERE MATCH_LEAGUE_ID =" + league_id + ";"
    cursor = connection.cursor()
    cursor.execute(sql_string)
    matches = cursor.fetchall()

    home_team_ids = list(match[1] for match in matches)
    away_team_ids = list(match[2] for match in matches)
    team_ids = list(set(home_team_ids + away_team_ids))

    sql_string = "SELECT TEAM_ID, TEAM_NAME FROM sentiosp_drupal6.td_team WHERE "

    for team_id in team_ids:
        sql_string += " TEAM_ID = " + str(team_id) + " OR"

    sql_string += " FALSE"
    cursor = connection.cursor()
    cursor.execute(sql_string)
    returned_data = cursor.fetchall()
    team_names = dict(returned_data)

    data = list()

    for match in matches:
        try:
            data.append((match[0], team_names[match[1]], team_names[match[2]] ))
        except:
            print match
    return HttpResponse(simplejson.dumps(data), mimetype='application/json')
Пример #2
0
def grammas(splitedString, n, k):
    gramsDict = dict()  #dict for all n-gramms
    for j in range(len(splitedString)):  #check all words
        if len(splitedString[j]) >= n:  #if word > n-gramm
            for x in range(len(splitedString[j]) - n):  #find n-gramm in word
                sr = splitedString[j][x:x + n]  #cut n-gramm from word
                if gramsDict.get(sr, 'n') == 'n':
                    gramsDict[sr] = 1
                else:
                    a = gramsDict[sr]  #if n-gramm already exist, a++
                    a += 1
                    gramsDict[sr] = a
        else:
            continue
    sortedGramsDict = sorted(gramsDict.items(),
                             key=lambda y: y[1],
                             reverse=True)  #sort of dict
    list1 = [sortedGramsDict[i][1] for i in range(len(sortedGramsDict))]
    print('Top {} {}-gramm:'.format(k, n))
    for i in range(k):
        o = list1[0]
        p = list1.count(o)
        print(i + 1, ':')
        for j in range(p):
            list1.remove(o)
            print(sortedGramsDict[0])
            del sortedGramsDict[0]
        if len(sortedGramsDict) == 0:
            break
Пример #3
0
def my_ajax_view(request):
#    if not request.is_ajax():
#        raise Http404
    if request.is_ajax():
        data_dict = dict(returnValue = request.GET.get('sendValue'))

        return HttpResponse(simplejson.dumps(data_dict), mimetype='application/json')
Пример #4
0
def word_in_string(splitedString):
    dictionary = dict()
    for item in splitedString:
        if item in dictionary.keys():
            dictionary[item] += 1
        else:
            dictionary[item] = 1
    return dictionary
Пример #5
0
def test(request):
    d = dict(user = request.user, leagues = load_leagues())
    return render_to_response("test.html", d)
Пример #6
0
 def __init__(self):
     super().__init__()
     self._Nod = dict()
     self._split_roads = list()
Пример #7
0
 def __init__(self):
     self._Data = dict()