some more queries from consultancy 1

refactor-to-mono
Giò Diani 2024-10-26 18:02:53 +02:00
parent 00ee0c5847
commit d5f8f21308
1 changed files with 64 additions and 3 deletions

View File

@ -9,11 +9,72 @@ class Database:
return self.connection.sql("DESCRIBE;").show()
def seeds(self):
return self.connection.sql("SELECT regions.name, seeds.uri FROM consultancy_d.regions LEFT JOIN consultancy_d.seeds ON regions.id = seeds.region_id;").show()
return self.connection.sql("""
SELECT
regions.name,
seeds.uri
FROM
consultancy_d.regions
LEFT JOIN
consultancy_d.seeds ON regions.id = seeds.region_id;
""").show()
def properties_growth(self):
return self.connection.sql("SELECT strftime(created_at, '%Y-%m-%d') AS date, COUNT(*) as properties_count FROM consultancy_d.properties GROUP BY date;").show()
return self.connection.sql("""
SELECT
strftime(created_at, '%Y-%m-%d') AS date,
COUNT(*) as properties_count
FROM
consultancy_d.properties
GROUP BY
date;
""").show()
def properties_per_region(self):
return self.connection.sql("SELECT regions.name, COUNT(*) AS count_properties FROM consultancy_d.properties LEFT JOIN consultancy_d.seeds ON seeds.id = properties.seed_id LEFT JOIN consultancy_d.regions ON regions.id = seeds.region_id GROUP BY properties.seed_id, regions.name").show()
return self.connection.sql("""
SELECT
regions.name,
COUNT(*) AS count_properties
FROM
consultancy_d.properties
LEFT JOIN
consultancy_d.seeds ON seeds.id = properties.seed_id
LEFT JOIN
consultancy_d.regions ON regions.id = seeds.region_id
GROUP BY
properties.seed_id,
regions.name
""").show()
def properties_unreachable(self):
return self.connection.sql("""
SELECT
entity_id,
strftime(properties.created_at, '%Y-%m-%d') AS first_found,
strftime(properties.last_found, '%Y-%m-%d') AS last_found
FROM
consultancy_d.exceptions
LEFT JOIN
consultancy_d.properties ON properties.id = exceptions.entity_id
WHERE
JSON_VALID(exception) = true AND
JSON_EXTRACT(exception, '$.status') = '404'
GROUP BY ALL
ORDER BY
last_found
""").show()
def properties_not_found(self):
return self.connection.sql("""
SELECT
COUNT(entity_id) as count_props,
strftime(created_at, '%Y-%m-%d') as date
FROM
consultancy_d.exceptions
WHERE
JSON_VALID(exception) = true AND
JSON_EXTRACT(exception, '$.status') > 400
GROUP BY
date
""").show()