Exemplo n.º 1
0
def get_results(search_terms):
    connection = ds.establish_connection(ds.TEAM_CREDENTIALS)
    data_source = ds.DataSource(connection)
    results = None

    order_by = search_terms.get('order')
    # Protect from unexpected query terms
    search_terms = {
        field: value
        for field, value in search_terms.items() if is_valid_field(field)
    }
    for search_term in search_terms.items():
        field_results = get_field_results(data_source, search_term)
        if field_results is None:
            continue
        # If multiple search terms, get intersection
        if results is None:
            results = field_results
        else:
            results = [result for result in results if result in field_results]

    connection.close()

    if results is None:
        return []
    elif order_by is not None:
        sort_results_by_field(results, order_by)

    return results
Exemplo n.º 2
0
def main():
    global app

    # sys.argv.extend(['-platform', 'eglfs'])

    # Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used.
    app = QApplication(sys.argv)

    viewer = QQuickView()

    # The following are needed to make examples run without having to install the module
    # in desktop environments.
    extraImportPath = QGuiApplication.applicationDirPath()
    if sys.platform == 'win32':
        extraImportPath += "/../../../../qml"
    else:
        extraImportPath += "/../../../qml"

    viewer.engine().addImportPath(extraImportPath)
    viewer.engine().quit.connect(app.quit)

    viewer.setTitle("QML Oscilloscope")

    dataSource = datasource.DataSource(viewer)
    viewer.rootContext().setContextProperty("dataSource", dataSource)

    main_qml = path.dirname(__file__) + "/qml/qmloscilloscope/main.qml"
    viewer.setSource(QUrl(main_qml))
    viewer.setResizeMode(QQuickView.SizeRootObjectToView)
    viewer.setColor(QColor("#404040"))
    viewer.show()

    return app.exec_()
Exemplo n.º 3
0
def get_all_unique_values():
    connection = ds.establish_connection(ds.TEAM_CREDENTIALS)
    data_source = ds.DataSource(connection)
    unique_values = {
        field: data_source.get_unique_values(field)
        for field in ds.DB_ENTRY_FIELDS
    }
    connection.close()

    return unique_values
Exemplo n.º 4
0
def respond():
    data = datasource.DataSource()
    data.update_data()
    # pprint.pprint(data.data)
    with open('data.json', 'w') as outfile:
        for article in data.data:
            article['wordchoice'] = [
                x.__dict__['string'] for x in article['wordchoice']
            ]
        json.dump(data.data, outfile)
        return 'blah'
def result():
    if request.method == 'POST':
        inputCategory = request.form['Category']
        inputTime = request.form['Time']
        inputAge = request.form['Minimum Age']
        inputNumPlayer = request.form['No. of Players']
        info = datasource.DataSource(inputNumPlayer, inputAge, inputCategory, inputTime)
        query = info.search()
        if query == "Sorry! No games found":        
            return render_template('noResults.html')
        else:
            return render_template("results.html",result = query)
Exemplo n.º 6
0
def renderResultTimeUsageRange():
    result = datasource.DataSource("diiannic", "corn972corn")
    state = request.args.get("state")
    activity = request.args.get("activity")
    start = request.args.get("start")
    end = request.args.get("end")
    if ((start == "---") and (end == "---")):
        stateMins = result.getActivityMinsByState(state, activity)
        start = 2014
        end = 2018
        year_message = "from " + str(start) + " to " + str(end)
        peopleSurveyed = result.getNumberOfPeopleSurveyedByStateAverage(
            state, start, end)
    elif (end == "---"):
        start = int(start)
        end = start
        year_message = "in " + str(start)
        stateMins = result.getActivityAverageMinsByYearAndState(
            start, state, activity)
        peopleSurveyed = result.getNumberOfPeopleSurveyedByStateAndYear(
            state, start)
    elif (start == "---"):
        end = int(end)
        start = end
        year_message = "in " + str(end)
        stateMins = result.getActivityAverageMinsByYearAndState(
            end, state, activity)
        peopleSurveyed = result.getNumberOfPeopleSurveyedByStateAndYear(
            state, end)
    else:
        start = int(start)
        end = int(end)
        if (start > end):
            temp = start
            start = end
            end = temp
        if start == end:
            year_message = "in " + str(start)
        else:
            year_message = "from " + str(start) + " to " + str(end)
        stateMins = result.getActivityMinsByStateRange(state, activity, start,
                                                       end)
        peopleSurveyed = result.getNumberOfPeopleSurveyedByStateAverage(
            state, start, end)

    plt.clf()
    createPlot(start, end, stateMins)

    return render_template('sample_results.html',
                           peopleSurveyed=peopleSurveyed,
                           type=activity + " Time Usage",
                           state=state,
                           year=year_message)
Exemplo n.º 7
0
async def ftp_handler(reader, writer):
    session = ftpsession.FtpSession(
        HOST,
        reader,
        writer,
        datasource.DataSource(HTTP_SESSION)
    )
    try:
        try:
            await session.dispatch()
        finally:
            await session.close()
    except ftpsession.DropSession:
        pass
    except BrokenPipeError:
        pass
    except ConnectionResetError:
        pass
def tableComparison():

    if request.method == 'POST':

        field1 = request.form["DV1"]
        field2 = request.form["DV2"]
        spotlight = request.form["SL"]
        staffpick = request.form["SP"]

        ds = datasource.DataSource()
        ds.connect('beckerr2', 'barn787sign')

        if (field1 == "Backer Count" and field2 == "Pledged Amount"
                and spotlight == "IDC" and staffpick == "IDC"):

            table = []
            table = ds.getBackersAndPledged()

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                pledged = ds.convertCurrency(row[1], currency)
                rowX = [row[0], pledged]
                newTable.append(rowX)
                i = i + 1

            bestTable = []
            for row in table:
                for index in row:
                    bestTable.append(index)

            newtable_json = json.dumps(newTable)

            return render_template('datapage_table.html',
                                   table=table,
                                   field1=field1,
                                   field2=field2,
                                   newTable=newtable_json)
    return render_template('datapage_table.html')
 def __init__(self):
     '''Has several methods to return HTML code for printing in index.py'''
     self.data = datasource.DataSource()
     self.form = cgi.FieldStorage()
Exemplo n.º 10
0
def get_results():
    '''
    Gets fields of submitted query and calls DB API with the query params.

    Returns:
        -results.html page formatted with comments
    '''

    comments = []
    errors = []
    ds = datasource.DataSource()

    #initializes booleans for filtering purposes
    badSentBool = False
    goodSentBool = False
    maxScoreBool = False
    minScoreBool = False

    if request.method == 'POST':

        print(request.form)
        # get keywords, other comment specs from submitted form

        #A series of try commands that conditionally execute queries based on user input
        try:
            keywords = request.form['keywords']
            if keywords != "":
                queryResult = ds.KeywordSearch(keywords)
                for comment in queryResult:
                    if comment in comments:
                        pass
                    else:
                        comments.append(comment)
                keywordBool = True
        except:
            pass

        try:
            goodSentiment = request.form['goodSentiment']
            goodSentBool = True
        except:
            pass

        try:
            badSentiment = request.form['badSentiment']
            badSentBool = True
        except:
            pass
        #returns everything if both good and bad sentiment are selected
        if badSentBool and goodSentBool:
            badSentBool = False
            goodSentBool = False

        elif badSentBool and not goodSentBool:
            queryResult = ds.getSentimentBad()
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)

        elif goodSentBool and not badSentBool:
            queryResult = ds.getSentimentGood()
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)
        #sets filtering booleans for a score query
        try:
            scoreLow = request.form['scoreLow']
            if scoreLow != '':
                minScoreBool = True
        except:
            pass

        try:
            scoreHigh = request.form['scoreHigh']
            if scoreHigh != '':
                maxScoreBool = True
        except:
            pass
        #begins appending the queries into a comment array 
        if minScoreBool and maxScoreBool:
            queryResult = ds.getScoreInRange(scoreLow, scoreHigh)
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)

        if minScoreBool and not maxScoreBool:
            queryResult = ds.getScoreAbove(scoreLow)
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)

        if maxScoreBool and not minScoreBool:
            queryResult = ds.getScoreBelow(scoreHigh)
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)

        try:
            edited = request.form['edited']
            queryResult = ds.getEdited('TRUE')
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)
            editedBool = True
        except:
            pass

        try:
            gilded = request.form['gilded']
            queryResult = ds.getGuilded()
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)
            gildedBool = True
        except:
            pass

        try:
            controversial = request.form['controversial']
            queryResult = ds.getControversial()
            for comment in queryResult:
                if comment in comments:
                    pass
                else:
                    comments.append(comment)
            controvBool = True
        except:
            pass

        #removes comments that dont fit the query conditions
        Results = filterResults(comments, request.form)
        #comment array is pushed to be rendered
        return render_template('resultsTemplate.html', comments=Results)
def defaultComparison():
    if request.method == 'POST':

        field1 = request.form["DV1"]
        field2 = request.form["DV2"]
        spotlight = request.form["SL"]
        staffpick = request.form["SP"]

        ds = datasource.DataSource()
        ds.connect('beckerr2', 'barn787sign')
        if (spotlight == "True"):
            spot = "t"
        elif (spotlight == "False"):
            spot = "f"
        else:
            spot = ""

        if (staffpick == "True"):
            staff = "t"
        elif (staffpick == "False"):
            staff = "f"
        else:
            staff = ""

        if (field1 == "Backer Count" and field2 == "Pledged Amount"):

            table = []
            table = ds.getBackersAndPledged(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                pledged = ds.convertCurrency(row[1], currency)
                rowX = [row[0], pledged]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field1,
                                   field2=field2,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)

        elif (field1 == "Pledged Amount" and field2 == "Backer Count"):
            table = []
            table = ds.getBackersAndPledged(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                pledged = ds.convertCurrency(row[1], currency)
                rowX = [pledged, row[0]]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field2,
                                   field2=field1,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)

        elif (field1 == "Backer Count" and field2 == "Goal"):
            table = []
            table = ds.getBackersAndGoal(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                goal = ds.convertCurrency(row[1], currency)
                rowX = [row[0], goal]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field1,
                                   field2=field2,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)

        elif (field1 == "Goal" and field2 == "BackerCount"):
            table = []
            table = ds.getBackersAndGoal(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                goal = ds.convertCurrency(row[1], currency)
                rowX = [goal, row[0]]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field2,
                                   field2=field1,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)
        elif (field1 == "Pledged Amount" and field2 == "Goal"):
            table = []
            table = ds.getPledgedAndGoal(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                pledged = ds.convertCurrency(row[0], currency)
                goal = ds.convertCurrency(row[1], currency)
                rowX = [pledged, goal]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field1,
                                   field2=field2,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)

        elif (field1 == "Goal" and field2 == "Pledged Amount"):
            table = []
            table = ds.getPledgedAndGoal(spot, staff)

            newTable = []
            i = 0
            for row in table:
                currency = row[2]
                pledged = ds.convertCurrency(row[0], currency)
                goal = ds.convertCurrency(row[1], currency)
                rowX = [goal, pledged]
                newTable.append(rowX)
                i = i + 1

            newtable_json = json.dumps(newTable)

            return render_template('datapage.html',
                                   table=table,
                                   field1=field2,
                                   field2=field1,
                                   newTable=newtable_json,
                                   spotlight=spotlight,
                                   staffpick=staffpick)

    return render_template('datapage.html')
def chartComparison():

    ###TO_DO###

    if request.method == 'POST':

        #Casting Data from User

        ds = datasource.DataSource()
        ds.connect('beckerr2', 'barn787sign')

        minBackers = int(request.form["backers_min"])
        maxBackers = int(request.form["backers_max"])
        minPledged = int(request.form["pledged_min"])
        maxPledged = int(request.form["pledged_max"])
        minGoal = int(request.form["goal_min"])
        maxGoal = int(request.form["goal_max"])
        displayVariable = request.form["DV"]

        chartData = []

        if (displayVariable == "Spotlight"):
            isSpotlightedCount = 0
            isNotSpotlightedCount = 0  ###WORKINGHERE###

            if ((not (minBackers == 0 and maxBackers == 0))
                    and (not (minPledged == 0 and maxPledged == 0))
                    and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByAll(minBackers, maxBackers,
                                              minPledged, maxPledged, minGoal,
                                              maxGoal)

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                params = "All"

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackersPledged(
                    minBackers, maxBackers, minPledged, maxPledged)
                params = "BP"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByBackersGoal(minBackers, maxBackers,
                                                      minGoal, maxGoal)
                params = "BG"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByPledgedGoal(minPledged, maxPledged,
                                                      minGoal, maxGoal)
                params = "PG"

                a = 1
                i = 10000000000 ^ 10000000000000000000000000000000000000000000000000000000000000000000000000000000000
                breakYouGodDamnFool = i * 3.1415926
                while True:
                    a = a + 1
                    print("yaaaaaaaaaaas")

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackers(minBackers, maxBackers)
                params = "B"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByPledged(minPledged, maxPledged)
                params = "P"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByGoal(minGoal, maxGoal)
                params = "G"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByNone()
                params = "None"

                for row in chartData:
                    if (row[10] == "T"):
                        isSpotlightedCount = isSpotlightedCount + 1
                    elif (row[10] == "F"):
                        isNotSpotlightedCount = isNotSpotlightedCount + 1

                newTable = []

                row1 = ["Spotlighted", isSpotlightedCount]
                newTable.append(row1)

                row2 = ["Not Spotlighted", isNotSpotlightedCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            else:
                print("We f****d up")

        if (displayVariable == "Staffpick"):
            # all staffpick sorts:
            isStaffpickCount = 0
            isNotStaffpickCount = 0

            if ((not (minBackers == 0 and maxBackers == 0))
                    and (not (minPledged == 0 and maxPledged == 0))
                    and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByAll(minBackers, maxBackers,
                                              minPledged, maxPledged, minGoal,
                                              maxGoal)
                params = "All"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackersPledged(
                    minBackers, maxBackers, minPledged, maxPledged)
                params = "BP"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByBackersGoal(minBackers, maxBackers,
                                                      minGoal, maxGoal)
                params = "BG"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByPledgedGoal(minPledged, maxPledged,
                                                      minGoal, maxGoal)
                params = "PG"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackers(minBackers, maxBackers)
                params = "B"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByPledged(minPledged, maxPledged)
                params = "P"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByGoal(minGoal, maxGoal)
                params = "G"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByNone()
                params = "None"

                for row in chartData:
                    if (row[11] == "T"):
                        isStaffpickCount = isStaffpickCount + 1
                    elif (row[11] == "F"):
                        isNotStaffpickCount = isNotStaffpickCount + 1

                newTable = []

                row1 = ["Staff-Picked", isStaffpickCount]
                newTable.append(row1)

                row2 = ["Not Staff-Picked", isNotStaffpickCount]
                newTable.append(row2)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            else:
                print("We f****d up")

        if (displayVariable == "Status"):
            #all status sorts
            statusSuccess = 0
            statusFailed = 0
            statusCancelled = 0
            statusSuspended = 0
            statusLive = 0

            if ((not (minBackers == 0 and maxBackers == 0))
                    and (not (minPledged == 0 and maxPledged == 0))
                    and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByAll(minBackers, maxBackers,
                                              minPledged, maxPledged, minGoal,
                                              maxGoal)
                params = "All"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackersPledged(
                    minBackers, maxBackers, minPledged, maxPledged)
                params = "BP"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByBackersGoal(minBackers, maxBackers,
                                                      minGoal, maxGoal)
                params = "BG"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByPledgedGoal(minPledged, maxPledged,
                                                      minGoal, maxGoal)
                params = "PG"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((not (minBackers == 0 and maxBackers == 0))
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByBackers(minBackers, maxBackers)
                params = "B"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (not (minPledged == 0 and maxPledged == 0))
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByPledged(minPledged, maxPledged)
                params = "P"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (not (minGoal == 0 and maxGoal == 0))):
                chartData = ds.getFilterByGoal(minGoal, maxGoal)
                params = "G"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            elif ((minBackers == 0 and maxBackers == 0)
                  and (minPledged == 0 and maxPledged == 0)
                  and (minGoal == 0 and maxGoal == 0)):
                chartData = ds.getFilterByNone()
                params = "None"

                for row in chartData:
                    if (row[12] == "S"):
                        statusSuccess = statusSuccess + 1
                    elif (row[12] == "F"):
                        statusFailed = statusFailed + 1
                    elif (row[12] == "C"):
                        statusCancelled = statusCancelled + 1
                    elif (row[12] == "X"):
                        statusSuspended = statusSuspended + 1
                    elif (row[12] == "L"):
                        statusLive = statusLive + 1

                newTable = []

                row1 = ["Succesful", statusSuccess]
                newTable.append(row1)

                row2 = ["Failed", statusFailed]
                newTable.append(row2)

                row3 = ["Cancelled", statusCancelled]
                newTable.append(row3)

                row4 = ["Suspended", statusSuspended]
                newTable.append(row4)

                row5 = ["Live", statusLive]
                newTable.append(row5)

                newtable_json = json.dumps(newTable)

                return render_template('chartpage.html',
                                       displayVariable=displayVariable,
                                       newTable=newtable_json,
                                       params=params,
                                       minBackers=minBackers,
                                       maxBackers=maxBackers,
                                       minPledged=minPledged,
                                       maxPledged=maxPledged,
                                       minGoal=minGoal,
                                       maxGoal=maxGoal)

            else:
                print("We f****d up")
    return render_template('chartpage.html')
        plt.show()
        print("mean squared bias: {:.4f}".format(avg_sqrd_bias))
        print("mean variance: {:.4f}".format(avg_variance))
    return avg_sqrd_bias, avg_variance


def tune_experiment(num_trials, train_size, min_degree, max_degree, source):
    biases = []
    variances = []
    degrees = range(min_degree, max_degree)
    for degree in degrees:
        avg_sqrd_bias, avg_variance = bias_variance_experiment(num_trials,
                                                               train_size,
                                                               degree,
                                                               source,
                                                               display=False)
        biases.append(avg_sqrd_bias)
        variances.append(avg_variance)
    biases = np.array(biases)
    variances = np.array(variances)
    plt.plot(degrees, biases)
    plt.plot(degrees, variances)
    plt.plot(degrees, biases + variances)
    plt.legend(["mean sqrd bias", "variance", "sum"])
    plt.show()


if __name__ == "__main__":
    ds = datasource.DataSource()
    bias_variance_experiment(100, 30, 3, ds, True)
def random():
    info = datasource.DataSource(5, 21, "Puzzel", 200)
    query = info.getRandomGame()
    return render_template('results.html', result = query)
Exemplo n.º 15
0
    def test_created_class_based_on_target(self, name, target, klass, data,
                                           datasize_lazy, datasize):

        s = datasource.DataSource(target)
        self.assertIsInstance(s, klass)