Beispiel #1
0
def getPageAsHTML():
  ''' Constructs and returns an HTML formatted string that can be printed, and thus
      fill the webpage with content! This method also calls helper methods for
      generating the HTML for the rating form and for the CrimeScore display.
  '''

  page = CrimrHTMLBuilder.getTopOfHTML("CrimeScore")
  page += CrimrHTMLBuilder.getTopOfBody("CrimeScore")
  page += getCrimeScoreHTMLReadOut()

  # HTML for the explanatory part of the page, and the form:
  page += '''
      <h3> Rate the crimes that scare you!</h3>

        <p>For each crime category below, consider how scary those types of crimes are to you.</p>
        <p>Each category rating has been defaulted to 5, indicating a medium-level of fear for each type of crime. Adjust accordingly.</p>
        <i>(0 = not scary, 10 = horrifying)</i></br>

      <a href="readme.html"><i>Read the methodology section of our README for more information about this calculation.</i></a>
      </br>
      </br>

      <!-- Crime rating form:-->
      %s
    ''' % (getFormHTML())

  page += CrimrHTMLBuilder.getClosingHTML()

  return page
Beispiel #2
0
def getPageAsHTML():
    ''' Constructs and returns an HTML formatted string that can be printed, and thus
      fill the webpage with content! This method also calls helper methods for
      generating the HTML for the rating form and for the CrimeScore display.
  '''

    page = CrimrHTMLBuilder.getTopOfHTML("CrimeScore")
    page += CrimrHTMLBuilder.getTopOfBody("CrimeScore")
    page += getCrimeScoreHTMLReadOut()

    # HTML for the explanatory part of the page, and the form:
    page += '''
      <h3> Rate the crimes that scare you!</h3>

        <p>For each crime category below, consider how scary those types of crimes are to you.</p>
        <p>Each category rating has been defaulted to 5, indicating a medium-level of fear for each type of crime. Adjust accordingly.</p>
        <i>(0 = not scary, 10 = horrifying)</i></br>

      <a href="readme.html"><i>Read the methodology section of our README for more information about this calculation.</i></a>
      </br>
      </br>

      <!-- Crime rating form:-->
      %s
    ''' % (getFormHTML())

    page += CrimrHTMLBuilder.getClosingHTML()

    return page
Beispiel #3
0
def getDataAsHTML(crimeID):
    ''' Returns the crime info from the PSQL database and a google maps map,
        formatted into an HTML String. Will be placed directly into the output
        String of 'getPageAsHTML()'

        The embedded map is retrieved from a template file.
    '''

    outputString = ''
    try:
        dataFetcher = CrimeDataFetcher()

        currentCrimeData = dataFetcher.getCrimeFromID(crimeID)
        headers = [
            'Crime ID', 'Category', 'Description', 'Day of Week', 'Date',
            'District', 'Resolution', 'X', 'Y'
        ]
        outputString += CrimrHTMLBuilder.getHTMLVertTable(
            headers, currentCrimeData)

        xCoordinateFromTable = currentCrimeData[7]
        yCoordinateFromTable = currentCrimeData[8]

        # Google map embed:
        mapEmbed = CrimrHTMLBuilder.getTemplate('googleMapEmbed')
        # Fill in the coordinates:
        mapEmbed = mapEmbed.replace('[[X_COORDINATE]]',
                                    str(xCoordinateFromTable))
        mapEmbed = mapEmbed.replace('[[Y_COORDINATE]]',
                                    str(yCoordinateFromTable))

        outputString += mapEmbed

    except Exception, e:
        outputString += 'Connection error: %s' % e
Beispiel #4
0
def main():
    ''' Gets the parameters from cgi input or a random PSQL algorithm and prints
        the page.
    '''
    parameter = getParametersFromFormOrDefaults()
    print CrimrHTMLBuilder.getStartingSequence(),
    print getPageAsHTML(parameter)
Beispiel #5
0
def main():
    ''' Gets the parameters from cgi input or a random PSQL algorithm and prints
        the page.
    '''
    parameter = getParametersFromFormOrDefaults()
    print CrimrHTMLBuilder.getStartingSequence(),
    print getPageAsHTML(parameter)
Beispiel #6
0
def getDataAsHTML(crimeID):
    ''' Returns the crime info from the PSQL database and a google maps map,
        formatted into an HTML String. Will be placed directly into the output
        String of 'getPageAsHTML()'

        The embedded map is retrieved from a template file.
    '''

    outputString = ''
    try:
        dataFetcher = CrimeDataFetcher()

        currentCrimeData = dataFetcher.getCrimeFromID(crimeID)
        headers = ['Crime ID','Category','Description','Day of Week','Date','District','Resolution','X','Y']
        outputString += CrimrHTMLBuilder.getHTMLVertTable(headers,currentCrimeData)

        xCoordinateFromTable = currentCrimeData[7]
        yCoordinateFromTable = currentCrimeData[8]

        # Google map embed:
        mapEmbed = CrimrHTMLBuilder.getTemplate('googleMapEmbed')
        # Fill in the coordinates:
        mapEmbed = mapEmbed.replace('[[X_COORDINATE]]', str(xCoordinateFromTable))
        mapEmbed = mapEmbed.replace('[[Y_COORDINATE]]', str(yCoordinateFromTable))

        outputString += mapEmbed

    except Exception, e:
        outputString += 'Connection error: %s' % e
Beispiel #7
0
def getPageAsHTML(parameters):
    ''' Constructs and returns an HTML formatted string that can be printed, and thus
		fill the webpage with a form and, possibly, results
	'''

    page = CrimrHTMLBuilder.getTopOfHTML('CRIMR')
    page += CrimrHTMLBuilder.getTopOfBody('Homepage')

    page += '<h4>Search</h4>'
    page += getFormAsHTML(parameters)
    page += getSearchResultsAsHTML(parameters)

    page += CrimrHTMLBuilder.getNavigationLinks()
    page += CrimrHTMLBuilder.getClosingHTML()

    return page
Beispiel #8
0
def getPageAsHTML(parameters):
	''' Constructs and returns an HTML formatted string that can be printed, and thus
		fill the webpage with a form and, possibly, results
	'''

	page = CrimrHTMLBuilder.getTopOfHTML('CRIMR')
	page += CrimrHTMLBuilder.getTopOfBody('Homepage')

	page += '<h4>Search</h4>'
	page += getFormAsHTML(parameters)
	page += getSearchResultsAsHTML(parameters)

	page += CrimrHTMLBuilder.getNavigationLinks()
	page += CrimrHTMLBuilder.getClosingHTML()

	return page
Beispiel #9
0
def getFormAsHTML(parameters):
	'''
	Returns valid HTML as a string which represents the search form
	Will be placed directly into the output String of 'getPageAsHTML(parameters)'

	Uses an HTML template for the most part (assembles one form due for scalability purposes)
	'''

	html = CrimrHTMLBuilder.getTemplate('mainSearchForm')
	# Most of the search form options are for static elements of the dataset that
	#  aren't likely to change (e.g. days of week, districts). Thus they are
	#  hardcoded into the template file.

	# However, due to potential for new categories in future updates to the dataset,
	#  the category select form options are assembled by grabbing all the categories
	#  from the database:
	fetcher = CrimeDataFetcher()
	categories = fetcher.getListOfCategories()
	categoryFormString = ''
	for category in categories:
		categoryFormString += '<option value="%s" id="%s">%s</option>' % (category.lower(),category.lower(),category.title())
	html = html.replace('[[CATEGORIES_SELECT_FORM_OPTIONS]]', categoryFormString)

	#Preserve Search Form on page refresh
	#Keep values for the dropdown menus
	lowerDistricts = ["tenderloin", "central", "bayview", "ingleside", "mission", "northern", "park", "southern", "taraval", "richmond"]
	if 'district' in parameters and parameters['district'] in lowerDistricts:
		strToReplace = 'value="%s"' % parameters['district']
		replacementString = 'selected="selected" value="%s"' % parameters['district']
		html = html.replace(strToReplace, replacementString)

	lowerCats = []
	for s in categories:
		lowerCats.append(s.lower())
	if 'category' in parameters and parameters['category'] in lowerCats:
		strToReplace = 'value="%s"' % parameters['category']
		replacementString = 'selected="selected" value="%s"' % parameters['category']
		html = html.replace(strToReplace, replacementString)

	lowerDaysOfWeek = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
	if 'day' in parameters and parameters['day'] in lowerDaysOfWeek:
		strToReplace = 'value="%s"' % parameters['day']
		replacementString = 'selected="selected" value="%s"' % parameters['day']
		html = html.replace(strToReplace, replacementString)

	lowerResolutions = ['*all*', '*resolved*', '*unresolved*', 'arrest', 'book', 'cite', 'psychopathic', 'not prosecute']
	if 'resolution' in parameters and parameters['resolution'] in lowerResolutions:
		strToReplace = 'value="%s"' % parameters['resolution']
		replacementString = 'selected="selected" value="%s"' % parameters['resolution']
		html = html.replace(strToReplace, replacementString)

	# Keep the search box filled in:
	html = html.replace('[[SEARCH]]',parameters['search'])

	return html
Beispiel #10
0
def getPageAsHTML(crimeID):
    ''' Constructs and returns an HTML formatted string that can be printed,
        and thus fill the webpage with content!

        Always shows the links at the bottom and uses getDataAsHTML method to
        get a table of the information and map for the crime.
    '''

    page = CrimrHTMLBuilder.getTopOfHTML('CRIMR')
    page += CrimrHTMLBuilder.getTopOfBody('Crime Details')
    page += getDataAsHTML(crimeID)

    # The random crime button!
    page += '''
            <form action="CrimeDetails.py" method="get">
                <p><input type="submit" value="Get Unsolved Crime!" /></p>
            </form>
            '''

    page += CrimrHTMLBuilder.getClosingHTML()

    return page
Beispiel #11
0
def getPageAsHTML(crimeID):
    ''' Constructs and returns an HTML formatted string that can be printed,
        and thus fill the webpage with content!

        Always shows the links at the bottom and uses getDataAsHTML method to
        get a table of the information and map for the crime.
    '''

    page = CrimrHTMLBuilder.getTopOfHTML('CRIMR')
    page += CrimrHTMLBuilder.getTopOfBody('Crime Details')
    page += getDataAsHTML(crimeID)

    # The random crime button!
    page += '''
            <form action="CrimeDetails.py" method="get">
                <p><input type="submit" value="Get Unsolved Crime!" /></p>
            </form>
            '''

    page += CrimrHTMLBuilder.getClosingHTML()

    return page
Beispiel #12
0
def getSearchResultsAsHTML(parameters):
	''' Returns the search results from the PSQL database, formatted into an HTML String
		Will be placed directly into the output String of 'getPageAsHTML(parameters)'
	'''
	outputString = ''
	dataFetcher = CrimeDataFetcher()
	try:
		outputTable = dataFetcher.getCrimesForSearch(parameters)
		if outputTable is not None:	#print nothing if there was no search
			headers = ['Crime ID','Category','Description','Day of Week','Date','District','Resolution','X','Y']
			outputString += CrimrHTMLBuilder.getHTMLTable(headers,outputTable)
		else:
			outputString += 'Use the controls above to get searching'
	except Exception, e:
		outputString +=  'Connection/Cursor Error: %s' % e
Beispiel #13
0
def getSearchResultsAsHTML(parameters):
    ''' Returns the search results from the PSQL database, formatted into an HTML String
		Will be placed directly into the output String of 'getPageAsHTML(parameters)'
	'''
    outputString = ''
    dataFetcher = CrimeDataFetcher()
    try:
        outputTable = dataFetcher.getCrimesForSearch(parameters)
        if outputTable is not None:  #print nothing if there was no search
            headers = [
                'Crime ID', 'Category', 'Description', 'Day of Week', 'Date',
                'District', 'Resolution', 'X', 'Y'
            ]
            outputString += CrimrHTMLBuilder.getHTMLTable(headers, outputTable)
        else:
            outputString += 'Use the controls above to get searching'
    except Exception, e:
        outputString += 'Connection/Cursor Error: %s' % e
Beispiel #14
0
def getFormAsHTML(parameters):
    '''
	Returns valid HTML as a string which represents the search form
	Will be placed directly into the output String of 'getPageAsHTML(parameters)'

	Uses an HTML template for the most part (assembles one form due for scalability purposes)
	'''

    html = CrimrHTMLBuilder.getTemplate('mainSearchForm')
    # Most of the search form options are for static elements of the dataset that
    #  aren't likely to change (e.g. days of week, districts). Thus they are
    #  hardcoded into the template file.

    # However, due to potential for new categories in future updates to the dataset,
    #  the category select form options are assembled by grabbing all the categories
    #  from the database:
    fetcher = CrimeDataFetcher()
    categories = fetcher.getListOfCategories()
    categoryFormString = ''
    for category in categories:
        categoryFormString += '<option value="%s" id="%s">%s</option>' % (
            category.lower(), category.lower(), category.title())
    html = html.replace('[[CATEGORIES_SELECT_FORM_OPTIONS]]',
                        categoryFormString)

    #Preserve Search Form on page refresh
    #Keep values for the dropdown menus
    lowerDistricts = [
        "tenderloin", "central", "bayview", "ingleside", "mission", "northern",
        "park", "southern", "taraval", "richmond"
    ]
    if 'district' in parameters and parameters['district'] in lowerDistricts:
        strToReplace = 'value="%s"' % parameters['district']
        replacementString = 'selected="selected" value="%s"' % parameters[
            'district']
        html = html.replace(strToReplace, replacementString)

    lowerCats = []
    for s in categories:
        lowerCats.append(s.lower())
    if 'category' in parameters and parameters['category'] in lowerCats:
        strToReplace = 'value="%s"' % parameters['category']
        replacementString = 'selected="selected" value="%s"' % parameters[
            'category']
        html = html.replace(strToReplace, replacementString)

    lowerDaysOfWeek = [
        'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday',
        'saturday'
    ]
    if 'day' in parameters and parameters['day'] in lowerDaysOfWeek:
        strToReplace = 'value="%s"' % parameters['day']
        replacementString = 'selected="selected" value="%s"' % parameters['day']
        html = html.replace(strToReplace, replacementString)

    lowerResolutions = [
        '*all*', '*resolved*', '*unresolved*', 'arrest', 'book', 'cite',
        'psychopathic', 'not prosecute'
    ]
    if 'resolution' in parameters and parameters[
            'resolution'] in lowerResolutions:
        strToReplace = 'value="%s"' % parameters['resolution']
        replacementString = 'selected="selected" value="%s"' % parameters[
            'resolution']
        html = html.replace(strToReplace, replacementString)

    # Keep the search box filled in:
    html = html.replace('[[SEARCH]]', parameters['search'])

    return html
Beispiel #15
0
def main():
    ''' Prints the HTML page (using the CrimrHTMLBuilder where applicable)
  '''
    print CrimrHTMLBuilder.getStartingSequence()
    print(getPageAsHTML())
Beispiel #16
0
def main():
    ''' Gets the parameters from defaults or a cgi form, and prints the HTML page
	'''
    parameters = getParametersFromFormOrDefaults()
    print CrimrHTMLBuilder.getStartingSequence(),
    print(getPageAsHTML(parameters)),
Beispiel #17
0
def main():
  ''' Prints the HTML page (using the CrimrHTMLBuilder where applicable)
  '''
  print CrimrHTMLBuilder.getStartingSequence()
  print(getPageAsHTML())
Beispiel #18
0
def main():
	''' Gets the parameters from defaults or a cgi form, and prints the HTML page
	'''
	parameters = getParametersFromFormOrDefaults()
	print CrimrHTMLBuilder.getStartingSequence(),
	print(getPageAsHTML(parameters)),