#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan  5 13:39:48 2017

@author: brendontucker
"""

topicIds = [[1, 2, 3], [2, 3, 4], [1, 4], [2, 3]]
answerIds = [[6, 4], [1, 2], [5], [3]] 
views = [[2, 1, 2], [6, 3, 5], [3, 3, 0], [5, 1, 1], [4, 2, 3], [1, 4, 2]]

uniqueTopics = []

uniqueUsers = []

#yay I didn't use a while loop for once 
for topics in topicIds:
    for ids in topics:
        if ids not in uniqueTopics:
            uniqueTopics.append(ids)

#length of unique topics is length of output array 

counter = 0

while counter < len(views):
    if views[counter][1] not in uniqueUsers:
        uniqueUsers.append(views[counter][1])
        counter = counter + 1
    else:
        counter = counter + 1
        
uniqueUsers.sort()

#for x in range(len(uniqueTopics))
#[[float(y) for y in x] for x in l] 

viewStorage = [[[] for x in range(len(uniqueTopics)) ] for y in range(len(uniqueUsers)) ]
                
#okay, have an array for data now

counter = 0
counter2 = 0
counter3 = 0
counter4 = 0
answerNum = 0
answerPos = 0
topic_Id = 0
#not sure if counter is always going to catch the right userId position...
while counter < len(uniqueUsers):
    counter2 = 0
    while counter2 < len(views):
        if views[counter][1] == uniqueUsers[counter]: #also nned to add one to counter value?
            answerNum = views[counter][0]
            counter3 = 0
            while counter3 < len(answerIds): 
                if answerNum in answerIds[counter3]:
                    answerPos = counter3 #subtract by one here also?
                    
                    counter4 = 0
                    while counter4 < 1: #if empty else add #len(topicIds)
                        topic_Id = topicIds[answerPos][counter4] - 1
                        if viewStorage[counter][topic_Id] == []: 
                            viewStorage[counter][topic_Id].append(views[counter][2])
                            counter4 = counter4 + 1
                        else:
                            viewStorage[counter][topic_Id] = viewStorage[counter][topic_Id] + views[counter][2]
                            counter4 = counter4 + 1
                else:
                    counter3 = counter3 + 1
            counter2 = counter2 + 1
        else:
            counter2 = counter2 + 1
    
    counter = counter + 1
        