diff --git a/client/src/components/Search/MapViewerV4.jsx b/client/src/components/Search/MapViewerV4.jsx index 27d6ca1..c0ec66a 100644 --- a/client/src/components/Search/MapViewerV4.jsx +++ b/client/src/components/Search/MapViewerV4.jsx @@ -39,9 +39,7 @@ function useImageKey({ searchCoordinates, searchYears }) { const bbox = turf.bbox(buffered) // calculate start and end for searching - const allSearchYears = searchYears - .map((year) => Number(year.praxisyear)) - .sort() + const allSearchYears = searchYears.map((year) => Number(year.year)).sort() // create ISO strings const start_captured_at = new Date(allSearchYears[0], 0, 1).toISOString() diff --git a/client/src/components/Search/SearchBar.jsx b/client/src/components/Search/SearchBar.jsx index 5df53e1..c375ab3 100644 --- a/client/src/components/Search/SearchBar.jsx +++ b/client/src/components/Search/SearchBar.jsx @@ -17,6 +17,7 @@ import { import PrimaryResultsContainer from "./PrimarySearchResults" import searchIcon from "../../assets/img/search.png" import { ppRose } from "../../utils/colors" +import { DEFAULT_YEAR } from "../../utils/constants" class SearchBar extends Component { _inputRef = React.createRef() @@ -247,7 +248,7 @@ class SearchBar extends Component { searchTerm: "", searchType: "all", searchCoordinates: null, - searchYear: "2020", //this is hardcoded and can be more dynamic + searchYear: DEFAULT_YEAR, //this is hardcoded and can be more dynamic }) } } @@ -300,11 +301,8 @@ class SearchBar extends Component { > {searchYears.map((result) => { return ( - ) })} diff --git a/client/src/components/Search/TimeGraph.jsx b/client/src/components/Search/TimeGraph.jsx index c4402b4..743e366 100644 --- a/client/src/components/Search/TimeGraph.jsx +++ b/client/src/components/Search/TimeGraph.jsx @@ -13,9 +13,9 @@ function TimeGraph({ ownid }) { const graph_data = data .map((record) => { // cast data - const { praxisyear, count } = record + const { year, count } = record return { - year: new Date(praxisyear, 1, 1), + year: new Date(year, 1, 1), count: Number(count), } }) diff --git a/client/src/reducers/search.js b/client/src/reducers/search.js index c4cde13..10b18a5 100644 --- a/client/src/reducers/search.js +++ b/client/src/reducers/search.js @@ -6,6 +6,7 @@ import { UPDATE_DETAILED_SEARCH, UPDATE_SEARCH_BAR, } from "../actions/search" +import { DEFAULT_YEAR } from "../utils/constants" const initialSearchState = { searchBar: { @@ -13,7 +14,7 @@ const initialSearchState = { }, searchParams: { searchType: "all", - searchYear: "2020", + searchYear: DEFAULT_YEAR, searchTerm: "", searchCoordinates: null, }, diff --git a/client/src/utils/constants.js b/client/src/utils/constants.js new file mode 100644 index 0000000..79ec821 --- /dev/null +++ b/client/src/utils/constants.js @@ -0,0 +1 @@ +export const DEFAULT_YEAR = "2021" diff --git a/server/routes/detailedSearch.js b/server/routes/detailedSearch.js index b474384..e632b80 100644 --- a/server/routes/detailedSearch.js +++ b/server/routes/detailedSearch.js @@ -10,7 +10,7 @@ router.get("/", async (req, res) => { const years = await queries.queryPGDB({ PGDBQueryType: queries.AVAILABLE_PRAXIS_YEARS, }) - const searchYears = years.data.map((record) => record.praxisyear) + const searchYears = years.data.map((record) => record.year) // .filter((pyear) => Number(pyear) !== Number(year)); //filter the current year const { data } = await queries.queryPGDB({ diff --git a/server/routes/geojsonSearch.js b/server/routes/geojsonSearch.js index 36f8b1e..3a75221 100644 --- a/server/routes/geojsonSearch.js +++ b/server/routes/geojsonSearch.js @@ -15,7 +15,7 @@ router.get("/", async (req, res) => { code = null, place = null, coordinates = null, - year = "2020", + year = "2021", } = req.query let pgData, geoJSON, clientData, praxisDataType diff --git a/server/utils/queries.js b/server/utils/queries.js index 79ea2f2..df0c5be 100644 --- a/server/utils/queries.js +++ b/server/utils/queries.js @@ -34,7 +34,6 @@ async function queryPGDB({ ownid = null, coordinates = null, parpropid = null, - searchYears = [2015, 2016, 2017, 2018, 2019, 2020, 2021], searchRadius = 1000, year = null, q = null, @@ -59,7 +58,7 @@ async function queryPGDB({ INNER JOIN owner_taxpayer AS otp ON tp.owntax_id = otp.owntax_id INNER JOIN owner_count as OC ON otp.own_id = oc.own_id WHERE p.zipcode_sj LIKE '${code}%' - AND y.praxisyear = '${year}' + AND y.year = ${year} GROUP BY p.zipcode_sj ORDER BY avg_count DESC LIMIT 5; @@ -69,7 +68,7 @@ async function queryPGDB({ case PRIMARY_SPECULATOR: query = `SELECT * FROM owner_count WHERE own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' - AND praxisyear = '${year}' + AND year = ${year} AND count > 9 ORDER BY count DESC LIMIT 5;` @@ -83,8 +82,8 @@ async function queryPGDB({ FROM ( SELECT jsonb_build_object( 'type', 'Feature', - 'geometry', ST_AsGeoJSON(geometry, 6)::json, - 'properties', to_jsonb(inputs) - 'geometry' + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom' ) AS feature FROM ( SELECT * FROM zips_geom @@ -106,7 +105,9 @@ async function queryPGDB({ FROM ( SELECT DISTINCT z.geometry AS geometry, z.zipcode AS zipcode FROM zips_geom AS z - INNER JOIN parcels_${year} AS p ON ST_Intersects(geometry, p.geom_${year}) + INNER JOIN parcels AS p + ON p.year = ${year} + AND ST_Intersects(z.geometry, p.geom) ${createCodeSQLPredicate({ code, ownid, coordinates })} ) inputs ) features;` @@ -120,13 +121,14 @@ async function queryPGDB({ FROM ( SELECT jsonb_build_object( 'type', 'Feature', - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( - SELECT * FROM parcels_${year} - WHERE propzip LIKE '%${code}%' + SELECT * FROM parcels + WHERE year = ${year} + AND propzip LIKE '%${code}%' ) inputs ) features;` break @@ -139,13 +141,14 @@ async function queryPGDB({ FROM ( SELECT jsonb_build_object( 'type', 'Feature', - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( - SELECT * FROM parcels_${year} - WHERE own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' + SELECT * FROM parcels + WHERE year = ${year} + AND own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' ) inputs ) features;` break @@ -158,13 +161,14 @@ async function queryPGDB({ FROM ( SELECT jsonb_build_object( 'type', 'Feature', - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( - SELECT * FROM parcels_${year} - WHERE propzip LIKE '%${code}%' + SELECT * FROM parcels + WHERE year = ${year} + AND propzip LIKE '%${code}%' AND own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' ) inputs ) features;` @@ -178,13 +182,14 @@ async function queryPGDB({ FROM ( SELECT jsonb_build_object( 'type', 'Feature', - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( - SELECT * FROM parcels_${year} - WHERE own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' + SELECT * FROM parcels + WHERE year = ${year} + AND own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' AND propzip LIKE '%${code}%' ) inputs ) features;` @@ -200,8 +205,8 @@ async function queryPGDB({ SELECT jsonb_build_object( 'type', 'Feature', 'id', feature_id, - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( @@ -209,13 +214,14 @@ async function queryPGDB({ ST_SetSRID( ST_MakePoint(${longitude}, ${latitude}), 4326)::geography, - geom_${year}::geography) AS distance - FROM parcels_${year} - WHERE ST_Distance( + geom::geography) AS distance + FROM parcels + WHERE year = ${year} + AND ST_Distance( ST_SetSRID( ST_MakePoint(${longitude}, ${latitude}), 4326)::geography, - geom_${year}::geography) < ${searchRadius} + geom::geography) < ${searchRadius} ) inputs ) features;` break @@ -229,8 +235,8 @@ async function queryPGDB({ SELECT jsonb_build_object( 'type', 'Feature', 'id', feature_id, - 'geometry', ST_AsGeoJSON(geom_${year}, 6)::json, - 'properties', to_jsonb(inputs) - 'geom_${year}', + 'geometry', ST_AsGeoJSON(geom, 6)::json, + 'properties', to_jsonb(inputs) - 'geom', 'centroid', ST_AsText(centroid) ) AS feature FROM ( @@ -238,9 +244,10 @@ async function queryPGDB({ ST_SetSRID( ST_MakePoint(${longitude}, ${latitude}), 4326)::geography, - geom_${year}::geography) AS distance - FROM parcels_${year} - WHERE propzip LIKE'${code}%' + geom::geography) AS distance + FROM parcels + WHERE year = ${year} + AND propzip LIKE'${code}%' ) inputs ) features;` break @@ -258,27 +265,16 @@ async function queryPGDB({ // search for available geometry cols case DETAILED_RECORD_YEARS: - const geomCols = searchYears - .map( - (year) => ` - CASE WHEN ST_AsText(geom_${year}) = 'GEOMETRYCOLLECTION EMPTY' - THEN 'null' - ELSE '${year}' - END AS geom_${year} - ` - ) - .join(", ") - query = `SELECT - ${geomCols} - FROM parcel_property_geom - WHERE parprop_id = '${parpropid}'` + DISTINCT year + FROM property + WHERE prop_id = ${parpropid}` break // all the years in the DB to search case AVAILABLE_PRAXIS_YEARS: - query = `SELECT DISTINCT praxisyear FROM year - ORDER BY praxisyear DESC;` + query = `SELECT DISTINCT year FROM year + ORDER BY year DESC;` break case SPECULATORS_BY_CODE: @@ -289,7 +285,8 @@ async function queryPGDB({ INNER JOIN owner_taxpayer AS otp ON tp.owntax_id = otp.owntax_id INNER JOIN owner_count as OC ON otp.own_id = oc.own_id WHERE p.zipcode_sj LIKE '${code}%' - AND oc.praxisyear = '${year}' + AND p.year = ${year} + AND oc.year = ${year} ORDER BY oc.count DESC LIMIT 5 ` @@ -299,13 +296,14 @@ async function queryPGDB({ query = `SELECT DISTINCT p.zipcode_sj AS propzip, STRING_AGG(DISTINCT ot.own_id, ',') AS own_id, COUNT(ot.own_id) AS count FROM parcel_property_geom AS ppg - INNER JOIN property AS p ON ppg.parprop_id = p.parprop_id + INNER JOIN property AS p ON ppg.prop_id = p.prop_id INNER JOIN taxpayer_property AS tp ON p.prop_id = tp.prop_id INNER JOIN year AS y on tp.taxparprop_id = y.taxparprop_id INNER JOIN taxpayer AS t ON tp.tp_id = t.tp_id INNER JOIN owner_taxpayer AS ot ON t.owntax_id = ot.owntax_id WHERE ot.own_id LIKE '%${decodeURI(ownid).toUpperCase()}%' - AND y.praxisyear = '${year}' + AND y.year = ${year} + AND ppg.year = ${year} GROUP BY p.zipcode_sj, ot.own_id ORDER BY count DESC; ` @@ -319,10 +317,11 @@ async function queryPGDB({ (SELECT SUM(x.count)::INT as count, x.own_id as own_id, x.total FROM (SELECT DISTINCT own_id, COUNT(own_id)::INT as count, - (SELECT COUNT(feature_id) FROM parcels_${year} - WHERE propzip LIKE '%${code}%' )::INT AS total - FROM parcels_${year} - WHERE propzip LIKE '%${code}%' + (SELECT COUNT(feature_id) FROM parcels + WHERE year = ${year} AND propzip LIKE '%${code}%')::INT AS total + FROM parcels + WHERE year = ${year} + AND propzip LIKE '%${code}%' GROUP BY own_id) x GROUP BY own_id, total ORDER BY count DESC ) y;` @@ -335,28 +334,30 @@ async function queryPGDB({ x.own_id, x.count::int, x.propzip, y.total::int, (x.count::float / y.total::float) * 100 AS per FROM ( - SELECT DISTINCT COUNT(ppg1.geom_${year}) AS count, + SELECT DISTINCT COUNT(ppg1.geom) AS count, ot1.own_id AS own_id, p1.zipcode_sj AS propzip FROM parcel_property_geom AS ppg1 - INNER JOIN property AS p1 ON ppg1.parprop_id = p1.parprop_id + INNER JOIN property AS p1 ON ppg1.prop_id = p1.prop_id INNER JOIN taxpayer_property AS tp1 ON p1.prop_id = tp1.prop_id INNER JOIN year AS y1 on tp1.taxparprop_id = y1.taxparprop_id INNER JOIN taxpayer AS t1 ON tp1.tp_id = t1.tp_id INNER JOIN owner_taxpayer AS ot1 ON t1.owntax_id = ot1.owntax_id - WHERE ot1.own_id LIKE '%${ownid}%' - AND y1.praxisyear = '${year}' + WHERE ppg1.year = ${year} + AND ot1.own_id LIKE '%${ownid}%' + AND y1.year = ${year} GROUP BY ot1.own_id, p1.zipcode_sj ) x INNER JOIN ( - SELECT DISTINCT COUNT(ppg2.geom_${year}) AS total, + SELECT DISTINCT COUNT(ppg2.geom) AS total, p2.zipcode_sj AS propzip FROM parcel_property_geom AS ppg2 - INNER JOIN property AS p2 ON ppg2.parprop_id = p2.parprop_id + INNER JOIN property AS p2 ON ppg2.prop_id = p2.prop_id INNER JOIN taxpayer_property AS tp2 ON p2.prop_id = tp2.prop_id INNER JOIN year AS y2 on tp2.taxparprop_id = y2.taxparprop_id INNER JOIN taxpayer AS t2 ON tp2.tp_id = t2.tp_id INNER JOIN owner_taxpayer AS ot2 ON t2.owntax_id = ot2.owntax_id - AND y2.praxisyear = '${year}' + AND y2.year = ${year} + WHERE ppg2.year = ${year} GROUP BY p2.zipcode_sj ) y ON x.propzip = y.propzip ORDER BY propzip, own_id, count;` @@ -365,7 +366,7 @@ async function queryPGDB({ case SPECULATOR_BY_YEAR: /*Search property count by own_id by year*/ query = `SELECT DISTINCT COUNT(ot.own_id), - ot.own_id, y.praxisyear + ot.own_id, y.year FROM owner_taxpayer AS ot INNER JOIN taxpayer AS tp ON ot.owntax_id = tp.owntax_id @@ -374,7 +375,7 @@ async function queryPGDB({ INNER JOIN year AS y ON tpp.taxparprop_id = y.taxparprop_id WHERE ot.own_id = '${ownid}' - GROUP BY ot.own_id, y.praxisyear` + GROUP BY ot.own_id, y.year` break diff --git a/tf/dev/main.tf b/tf/dev/main.tf index 88e938c..2eb798f 100644 --- a/tf/dev/main.tf +++ b/tf/dev/main.tf @@ -223,10 +223,10 @@ module "rds" { engine_version = "14" family = "postgres14" major_engine_version = "14" - instance_class = "db.t4g.micro" + instance_class = "db.t4g.small" - allocated_storage = 5 - max_allocated_storage = 20 + allocated_storage = 20 + max_allocated_storage = 50 db_name = local.appname port = 5432