breanneboland/go-truck-yourself

语言: HTML

git: https://github.com/breanneboland/go-truck-yourself

我最近的Hackbright项目:一个使用Python,Flask,CSS,JavaScript,PostgreSQL和Google Maps的网络应用程序......
My final project for Hackbright: a web app that uses Python, Flask, CSS, JavaScript, PostgreSQL, and the Google Maps …
README.md (中文)

去卡车你自己,1.0

Go Truck Yourself使用旧金山的OpenData(以及一些双关语)来展示哪些食品卡车在哪些位置经营许可。该应用程序可让您通过卡车的名称或与城市存档的业务描述按日,地点和相关术语查找您真正的食品卡车爱情。

SF OpenData移动食品设施许可证 SF OpenData移动食品计划

您可以在她的网站或LinkedIn上了解有关开发人员的更多信息。

内容

  • 技术
  • 特征
  • 数据和争论
  • 查询
  • 结构和文件
  • 截图

技术

Go Truck Yourself建立在Flask服务器(使用Python构建)上。它使用SQL Alchemy来查询PostgreSQL数据库。这些地图是使用Google Maps API创建的,其中包含从源自所述数据库的各种JSON Feed创建的标记。其他好吃的东西:Jinja,JavaScript,jQuery,以及完全过多的咖啡。

特征

目前的特点 主页显示当天开放的卡车。每个点的InfoWindow™都是由旧金山存档的单一计划记录创建的。从InfoWindow,您可以了解卡车的名称,允许的小时,位置和业务细节;内部链接将您连接到卡车的详细信息页面,该页面显示其每周的所有位置以及其业务详细信息。

主页地图上方的按钮链接到显示按一周其他日期过滤的卡车位置的地图。每张地图上的搜索框都允许有针对性的缩放,因此您可以在一周中的任何一天查看您所在位置附近的食品卡车。

您可以通过导航滚动骰子并找到随机卡车,或者您可以按商家名称,食物类型或其他描述性字词或短语进行搜索,以查找与您的搜索字词匹配的卡车。搜索结果页面上的链接将您带到卡车详细信息页面。

建议卡车说明任何市政数据中不可避免的差距;通过该页面提交的信息将记录到txt文件中,以供将来研究和纳入。

未来的特点 该应用程序的未来计划包括:   - 将地图标记转换为数组,而不是直接从相关的JSON Feed创建它们,因为当前的方法使用Google Maps API限制过滤和其他显示选项   - 缓存所述阵列以获得更好的性能   - 组织数据抓取以增加现有数据库条目并在SF OpenData系统外添加卡车信息   - 从上述数据抓取中,将Yelp,Twitter和卡车官方网站的信息添加到卡车记录中   - 添加Twilio功能,通过文本返回卡车记录   - 自动API查询,用于刷新数据库,删除已删除的条目和添加新条目

数据争吵

与大多数数据库一样,SF OpenData提供的信息差异很大,以至于我的服务器需要一些意外事件来确保数据正确显示。尽管如此,考虑到表格的大小(计划许可表最高可达125,000行)以及可能拥有的管理员数量,数据非常干净。

服务器端进程会考虑空单元格,不一致和重叠的打开和关闭时间,以及一个表中但不是另一个表中的条目。由于这个原因,随机函数最初查询调度表而不是业务许可表;使用卡车业务许可表来执行此功能通常会返回卡车ID和信息,而无需任何相关的计划项目,从而导致无用的卡车详细信息页面。

卡车详细信息页面上列出的时间是通过组合每天的计划行来创建的,以创建完整的时间列表;然后对它们进行分类,并且最早和最晚的时间被拉动并格式化以创建可读的时间范围,在此期间卡车爱好者可以每天找到所述卡车。

查询

Go Truck Yourself中的大多数查询都是使用SQL Alchemy创建的,它以各种方式从PostgreSQL数据库中提取信息。两张表(卡车营业许可证和卡车时刻表许可证)通过营业许可表生成的外键连接;卡车计划许可表中的每个记录包括此ID(如果可用)以及计划行ID记录。

星期几映射使用星期几的字符串版本来获取正确的JSON;这是一个偶然的决定,因为在这个项目过程中的一个发现是Python和JavaScript编号在一周中的日子不同。 API包括字符串和整数形式的星期几信息,但奇怪的是,字符串版本被证明是更容易的选择。

从“关于”页面链接的一个功能直接使用SF OpenData API进行查询。最初决定使用从CSV创建的本地数据库是一种情况:这个应用程序是为了一个事件的演示而创建的,它需要独立于互联网访问,以确保它能够正常运行,即使wifi停止了可用。 (你永远不会知道,即使在湾区。)然而,这是另一个偶然的决定,因为这些特定的API数据库不接受使用SODA API的其他数据API上可用的模糊搜索方法。 (换句话说:它不喜欢。)因此,API特定的搜索非常严格定义,需要确切的商业名称才能获得结果。最后,它包含在练习使用API​​的特定说明,这就是为什么它隐藏在应用程序的关于页面。本地数据库搜索功能更加通用和有效。

结构体

requirements.txt 安装的系统依赖性。

food_truck_db_seed.py 该文件包含两个类,数据库结构和用于创建两个表格的CSV解析,这些表格为Go Truck Yourself提供了动力。

server.py 使页面聚集在一起的路由。

静态的 这包含Bootstrap的位置版本(请参阅前面提到的使用此应用程序尝试的wifi独立性),自定义CSS文件以及此应用程序中使用的一个(!)图像。

模板 此文件夹包含由Flask组合的各种HTML文件,以创建您希望现在可以看到的可爱,强大的应用程序。

卡车submissions.txt 这是记录提交建议以供将来访问的地方。

截图

Homepage

Day of Week Page

Truck Detail Page

Search Results

Submission Form

Submission Acceptance

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

Go Truck Yourself, v 1.0

Go Truck Yourself uses San Francisco’s OpenData (and a few puns) to display what food trucks are licensed to operate in which locations. The app lets you find your true food truck love by day, location, and relevant term in either the truck’s name or the business description on file with the city.

SF OpenData Mobile Food Facility Permits
SF OpenData Mobile Food Schedule

You can learn more about the developer at her site or on LinkedIn.

Contents

  • Technologies
  • Features
  • Data and wrangling it
  • Queries
  • Structure and files
  • Screenshots

Technologies

Go Truck Yourself is built on a Flask server (which is built with Python). It uses SQL Alchemy to query a PostgreSQL database. The maps are created using the Google Maps API with markers created from a variety of JSON feeds derived from said database. Other assorted goodies: Jinja, JavaScript, jQuery, and entirely too much coffee.

Features

Current Features
The homepage shows trucks scheduled to be open that day. Each point’s InfoWindow™ is created by a single schedule record on file with San Francisco. From that InfoWindow, you can learn the truck’s name, permitted hours, location, and business details; a link within connects you to the truck’s detail page, which shows all of its weekly locations alongside its business details.

Buttons above the homepage map link to maps that show truck locations filtered by the other days of the week. The search box on each map allows targeted zoom, so you can see which food trucks are near your location any day of the week.

You can roll the dice and find a random truck via the nav, or you can search by business name, food type, or other descriptive word or phrase to find trucks matching your search term. Links on the search results page take you to truck detail pages.

Suggest a Truck accounts for the inevitable gaps in any municipal data; information submitted through that page is recorded to a txt file for future research and inclusion.

Future Features
Future plans for this app include:
- Turning the map markers into arrays instead of creating them directly from the relevant JSON feed, as the current approach limits filtering and other display options with the Google Maps API
- Caching said arrays for better performance
- Organized data scraping to augment existing database entries and add information on trucks outside of the SF OpenData system
- From said data scraping, adding information from Yelp, Twitter, and the trucks’ official websites to the truck records
- Adding a Twilio feature that will return truck records via text
- An automated API query to refresh the database, removing deleted entries and adding new ones

Data Wrangling

Like most databases, the information available via SF OpenData varies enough that my server required a number of contingencies to ensure the data properly displayed. Still, considering the size of the tables (the schedule permit table tops 125,000 rows) and how many stewards it likely has, the data is remarkably clean.

Server-side processes account for empty cells, inconsistent and overlapping opening and closing times, and entries that are in one table but not the other. The random function initially queries the schedule table rather than the business permit table for this reason; using the truck business permit table for this function often returned truck IDs and information without any associated schedule items, which resulted in unhelpful truck detail pages.

The times listed on the truck detail pages are created by combining each day’s schedule rows to create a complete list of times; they are then sorted, and the earliest and latest times are pulled and formatted to create a readable range of times during which truck enthusiasts could find said truck each day.

Queries

The majority of the queries in Go Truck Yourself are made with SQL Alchemy, pulling information from a PostgreSQL database in a variety of ways. The two tables (truck business permits and truck schedule permits) are connected by a foreign key generated by the business permit table; each record in the truck schedule permits table includes this ID, if available, plus a schedule line ID record.

The day-of-week maps use a string version of the day of the week to get the correct JSON back; this was a fortuitous decision, as one discovery during the course of this project was that Python and JavaScript number the days of the week differently. The API includes day-of-the-week information in both string and integer form, but the string version proved, weirdly enough, to be the easier option.

One feature, linked from the About page, directly uses the SF OpenData API to query. The initial decision to use a local database created from a CSV was one of circumstance: this app was created for, among other reasons, presentation at an event, and it needed to work independently of internet access to ensure it would be functional, even if wifi stopped being available. (You never know, even in the Bay Area.) However, this was another fortuitous decision, as these particular API databases do not accept the fuzzy search method available on other data APIs that use the SODA API. (To put it another way: it doesn’t like like.) As a result, the API-specific search is pretty rigidly defined, requiring the exact business name to get results. In the end, it was included to practice using an API’s specific instructions, which is why it’s tucked into the app’s About page. The local database search is far more versatile and effective.

Structure

requirements.txt
System dependencies for installation.

food_truck_db_seed.py
This file contains the two classes, database structures, and CSV parsing used to create the two tables that fuel Go Truck Yourself.

server.py
The routes that make the pages come together.

static
This contains a location version of Bootstrap (see the previously mentioned wifi-independence attempted with this app), the custom CSS file, and the one (!) image used in this app.

templates
This folder contains the various HTML files that are combined by Flask to create the lovely, robust app you hopefully now see before you.

truck-submissions.txt
This is where submission suggestions are recorded for future access.

Screenshots

Homepage

Day of Week Page

Truck Detail Page

Search Results

Submission Form

Submission Acceptance