Ejemplo n.º 1
0
    def getSpecialWords(self):
        dataResponses = myStorage.get("expDataDict")
        wordData = {}
        for key in dataResponses:
            dataString = ""
            tupleList = dataResponses[key] # list of tuples
            for item in tupleList:
                tempString = dataString + " " + item[1] + " "
                dataString = tempString
            newDataString = re.sub('[:./,?!]', '', dataString)
            f = open('./test_data/workfile.txt', 'w')
            f.write(newDataString)
            f.close()
            myWordSearch = wordSearch(1,["workfile.txt"],False)
#            print myWordSearch.results
            resultString = ""
            searchResults = myWordSearch.results
#            print searchResults
            for item in searchResults:
                if ("HTTP" in item) or ("WWW" in item):
                    searchResults.remove(item)
            for i in range(0,len(searchResults)):
                if i < (len(searchResults)):
                    resultString += searchResults[i] + ", "
                elif i == len(searchResults):
                    resultString += (searchResults[i])
            wordData[resultString[:-2]] = key
        return wordData
Ejemplo n.º 2
0
def infoAnalyze():
    emailBody = []
    emailIntro = "URBAN TOMORROWS Website Report - " + str(datetime.now().strftime("%Y%m%d-%H%M%S"))
    emailBody.append(emailIntro)
    emailBody.append("============================================================")
    emailBody.append("")
    """ uses the gathered data to make reports """
    print "\n\n\n===============================================\nBeginning info analysis...\n==============================================="
#    print "Number of Submissions:\n---------------------------------------------"
    emailBody.append("Number of Submissions")
    emailBody.append("------------------------------------------------------------")
#    print "Questionnaire: " + str(myStorage.thingStore["D2015MAINMsgCount"])
    emailBody.append(("Questionnaire: " + str(myStorage.thingStore["D2015MAINMsgCount"])))
    emailBody.append(("Demographic Survey: " + str(myStorage.thingStore["D2015SUPPMsgCount"])))
#    print "Demographic Survey: " + str(myStorage.thingStore["D2015SUPPMsgCount"])
    dataResponses = myStorage.get("expDataDict")
#    print "\n---------------------------------------------\nShowing word search results for ALL (combination of all responses):..."
    fullWordList = []
#    ', '.join("%s=%r" % (key,val) for (key,val) in k.iteritems())
    for key in dataResponses:
        tempDict = myStorage.thingStore[key+"WORDS"]
        for item in tempDict:
            if ("HTTP" not in item) or ("WWW" not in item): 
                fullWordList.append(item)
    f = open('./test_data/wordworkfile.txt', 'w')
    f.write(' '.join(fullWordList))
    f.close()
    myWordSearch = wordSearch(1,["wordworkfile.txt"],True)
#    print myWordSearch.results
#    print myWordSearch.resultsList
    emailBody.append("")
    emailBody.append("Organized list of all words from all submissions and their frequencies")
    emailBody.append("------------------------------------------------------------")
    emailBody.append(myWordSearch.resultsList)
    wordString = ""
    countString = ""
    for result in myWordSearch.resultsList:
        wordString = wordString + " " + result[0]
        countString = countString + " " + str(result[1])
#    print wordString
    wordList = wordString.split(" ")
#    print countString
    countList = countString.split(" ")
    cohortSize = len(myWordSearch.resultsList)
    # email the above data
    sender = "*****@*****.**"
    recipient = "*****@*****.**"
    subject = emailIntro
    
    emailString = ""
#    
#    for category in emailBody:
#        if isinstance(category, basestring):
#            print category
#        elif type(category) is list:
##            print ":".join("(%s,%s)" % tup for tup in category)
#            for value in category: # for tuple in category
#                print ": ".join("(%s)" % part for part in value)
#                for part in value: #for part in the tuple
#                    print part
#                print type(value)
#            print ":".join("(%s,%s)" % tup for tup in category) + ", "
    
#    for item in emailBody:
#        if isinstance(item, basestring):
#            emailString = emailString + "\n" + item
#        elif type(item) is list:
#            listString = ""
#            for part in list:
#                listString += "\n" + part
##            emailString = emailString + "\n" + ": ".join(item)
#            emailString +=
#        elif type(item) is tuple:
#            tupleString = ""
#            for part in item:
#                tupleString += " " + part + ": "
#            emailString += "\n" + tupleString
    message_text = emailString
    file_dir = '../data/processed/'
    filename = (myStorage.get("generated_questionnaire_doc"))[18:]
#    complete_message = CreateMessageWithAttachment(sender, recipient, subject, message_text, file_dir, filename)
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)
    user_id = 'me'