Forum Moderators: open

Message Too Old, No Replies

neighborhoods -weekly/ weeks - statistics - perplexed

set up new db -

         

iggy99

4:40 pm on Mar 26, 2015 (gmt 0)

10+ Year Member



MYSQL

hello

i wish to help my neighborhood group

we want to collectively track crime statistics

we have 16 neighborhoods - each has a neighborhood captain

each week each 'captain' gets a map and excel list of all the crimes in the 'neighborhood' from police dept by email...

there are a total of 30 crimes we will track - from loitering to murder

the goal is to be able to query mysql db... in two ways

1) for safest neighborhood for most recent week - as well as most dangerous

2) for safest neighborhood for any week in history in db - as well as most dangerous

my idea is too assign a default numeric value to each type of crime - example loitering value of '1' murder value of '100' and fill the other 28 codes based on the egregiousness of each crime by code in database..

i am a bit perplexed as to how best set up database, to keep track of the crimes... week by week and quantity of each crime... (often we will have many car thefts for instance in a given week and maybe.. 3 or more armed robberies)... so they can be queried successfully

thank you for your thoughts on this

Iggy

LifeinAsia

5:22 pm on Mar 26, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What does the data look like from the police department? Is it summarized data or detailed? In other words, does it just like the count of each crime type for the prior week, or does it list each specific crime and date? What the data looks like can affect how you setup the tables.

Off the top of my head, I would:
1) Create the main data table that holds all the data for each neighborhood.
2) Create a lookup table that maps each crime type to its egregiousness value.
3) (optional) Instead of storing the crime names directly in (1) I would create a lookup table mapping each crime name to a number and storing the number in (1) instead of the crime name.

After importing the Excel files each week (it would be nicer if you could get the police department to send you 1 combined file for all 16 neighborhoods), then it's a rather trivial matter to query the tables, summing up the crimes and their respective values, grouping by neighborhood, and sorting by the sum for each neighborhood (lowest sum = safest, highest sum = most dangerous). You can use the same query, just use a date filter depending on which week you want to look at.

iggy99

5:44 pm on Mar 26, 2015 (gmt 0)

10+ Year Member



we actually get maps.. shows day date - and crime.. we will have to key it in using forms... each week... we are trying to get police to send excel file,, they don't want to share info - part of the problem - for now we will have to extrapolate the data from each neighorhood map - here is one map for instance.. for one neighborhood one week..

[content.govdelivery.com ]

LifeinAsia

6:08 pm on Mar 26, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



they don't want to share info
Transparency in action! Yuck (in regards to the manual entry).

The my tables would look something like this:
(1) crime_list- autoid | neighborhoodid | crime_date | crime_id
1 | 1 | "2015-03-17 21:00" | 1
2 | 1 | "2015-03-17 17:00" | 2
...

(2) crime_egregiousness- crime_id | egregiousness
1 | 25
2 | 50
...
(3) crime_names- crime_id | crime_name
1 | TFVM
2 | BURGD
...

Oh, and a neighbohood lookup table:
(4) neighborhoods- neighborhoodid | neighborhood_name
1 | Ryan Lake
2 | Potters' Cove
...

Then the query would be something like:
SELECT n.neighborhood_name, SUM(ce.egregiousness) AS crime_total
FROM neighborhoods n
INNER JOIN crime_list cl ON n.neighborhoodid=cl.neighborhoodid
INNER JOIN crime_names cn ON cl.crime_id=cn.crime_id
INNER JOIN rime_egregiousness ce ON cl.crime_id=ce.crime_id
WHERE WEEK(cl.crime_date)=WEEK("2015-03-23")
GROUP BY n.neighborhood_name
ORDER BY crime_total