value error rectified
This commit is contained in:
parent
e1902330a1
commit
e62230cc10
@ -230,14 +230,24 @@ class ChartFormatter {
|
|||||||
// Create labels (months) sorted chronologically
|
// Create labels (months) sorted chronologically
|
||||||
const labels = Object.keys(monthData).sort();
|
const labels = Object.keys(monthData).sort();
|
||||||
|
|
||||||
|
// Get topCount from parsedQuery - if null/undefined, show all areas
|
||||||
|
const topCount = parsedQuery?.topCount;
|
||||||
|
|
||||||
// Create datasets for each area
|
// Create datasets for each area
|
||||||
const datasets = [];
|
const datasets = [];
|
||||||
const areaColors = [
|
const areaColors = [
|
||||||
'#3B82F6', '#EF4444', '#10B981', '#F59E0B', '#8B5CF6',
|
'#3B82F6', '#EF4444', '#10B981', '#F59E0B', '#8B5CF6',
|
||||||
'#EC4899', '#06B6D4', '#84CC16', '#F97316', '#6366F1'
|
'#EC4899', '#06B6D4', '#84CC16', '#F97316', '#6366F1',
|
||||||
|
'#F43F5E', '#8B5A2B', '#64748B', '#0EA5E9', '#A855F7',
|
||||||
|
'#14B8A6', '#EAB308', '#FBBF24', '#22C55E', '#06B6D4'
|
||||||
];
|
];
|
||||||
|
|
||||||
Array.from(areas).slice(0, 10).forEach((area, index) => { // Limit to 10 areas for readability
|
// If topCount is specified, limit; otherwise show all areas
|
||||||
|
const areasToShow = topCount !== null && topCount !== undefined
|
||||||
|
? Array.from(areas).slice(0, topCount)
|
||||||
|
: Array.from(areas);
|
||||||
|
|
||||||
|
areasToShow.forEach((area, index) => {
|
||||||
const areaData = labels.map(month => monthData[month][area] || null);
|
const areaData = labels.map(month => monthData[month][area] || null);
|
||||||
|
|
||||||
datasets.push({
|
datasets.push({
|
||||||
@ -521,6 +531,7 @@ class ChartFormatter {
|
|||||||
|
|
||||||
const counts = data.map(row => {
|
const counts = data.map(row => {
|
||||||
const count = row.transaction_count ||
|
const count = row.transaction_count ||
|
||||||
|
row.total_offplan_transactions ||
|
||||||
row.count ||
|
row.count ||
|
||||||
row.rental_count ||
|
row.rental_count ||
|
||||||
row.commercial_count ||
|
row.commercial_count ||
|
||||||
|
|||||||
@ -125,7 +125,7 @@ class ContextAwareSQLGenerator {
|
|||||||
limit: parsedQuery.refinements?.limit || 10,
|
limit: parsedQuery.refinements?.limit || 10,
|
||||||
roomType: null,
|
roomType: null,
|
||||||
projectName: parsedQuery.projectName || null,
|
projectName: parsedQuery.projectName || null,
|
||||||
topCount: parsedQuery.topCount || 5
|
topCount: parsedQuery.topCount !== undefined && parsedQuery.topCount !== null ? parsedQuery.topCount : null
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract room type for BHK queries
|
// Extract room type for BHK queries
|
||||||
|
|||||||
@ -311,45 +311,60 @@ class QueryTemplates {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Q10: Avg price of 3BHK apartment by area (monthly grouping, top 5)
|
// Q10: Avg price of 3BHK apartment by area (monthly grouping, top 5)
|
||||||
bhk_apartment_price: (params) => ({
|
bhk_apartment_price: (params) => {
|
||||||
sql: `
|
const topCount = params.topCount;
|
||||||
WITH monthly_avg AS (
|
// If topCount is specified, use it; otherwise show all areas
|
||||||
SELECT
|
const limitClause = topCount !== null && topCount !== undefined ? `LIMIT ${topCount}` : '';
|
||||||
DATE_FORMAT(start_date, '%Y-%m') AS month,
|
|
||||||
area_en,
|
return {
|
||||||
AVG(annual_amount) AS avg_price,
|
sql: `
|
||||||
COUNT(*) AS transaction_count,
|
WITH monthly_avg AS (
|
||||||
AVG(actual_area) AS avg_area
|
SELECT
|
||||||
FROM rents
|
DATE_FORMAT(start_date, '%Y-%m') AS month,
|
||||||
WHERE rooms = ?
|
area_en,
|
||||||
AND (prop_sub_type_en = 'flat' OR prop_sub_type_en = 'villa')
|
AVG(annual_amount) AS avg_price,
|
||||||
AND start_date >= ?
|
COUNT(*) AS transaction_count,
|
||||||
AND area_en IS NOT NULL
|
AVG(actual_area) AS avg_area
|
||||||
AND annual_amount IS NOT NULL
|
FROM rents
|
||||||
AND annual_amount > 0
|
WHERE rooms = ?
|
||||||
|
AND (prop_sub_type_en = 'flat' OR prop_sub_type_en = 'villa')
|
||||||
|
AND start_date >= ?
|
||||||
|
AND area_en IS NOT NULL
|
||||||
|
AND annual_amount IS NOT NULL
|
||||||
|
AND annual_amount > 0
|
||||||
GROUP BY month, area_en
|
GROUP BY month, area_en
|
||||||
HAVING transaction_count >= 1
|
HAVING transaction_count >= 1
|
||||||
),
|
),
|
||||||
ranked_areas AS (
|
top_areas AS (
|
||||||
SELECT
|
SELECT
|
||||||
month,
|
|
||||||
area_en,
|
area_en,
|
||||||
avg_price,
|
SUM(transaction_count) AS total_transactions,
|
||||||
transaction_count,
|
AVG(avg_price) AS overall_avg_price
|
||||||
ROW_NUMBER() OVER (PARTITION BY month ORDER BY avg_price DESC) AS rn
|
|
||||||
FROM monthly_avg
|
FROM monthly_avg
|
||||||
|
GROUP BY area_en
|
||||||
|
ORDER BY total_transactions DESC, overall_avg_price DESC
|
||||||
|
${limitClause}
|
||||||
|
),
|
||||||
|
filtered_monthly AS (
|
||||||
|
SELECT
|
||||||
|
ma.month,
|
||||||
|
ma.area_en,
|
||||||
|
ma.avg_price,
|
||||||
|
ma.transaction_count
|
||||||
|
FROM monthly_avg ma
|
||||||
|
INNER JOIN top_areas ta ON ma.area_en = ta.area_en
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
month,
|
month,
|
||||||
area_en,
|
area_en,
|
||||||
ROUND(avg_price, 2) AS avg_price,
|
ROUND(avg_price, 2) AS avg_price,
|
||||||
transaction_count
|
transaction_count
|
||||||
FROM ranked_areas
|
FROM filtered_monthly
|
||||||
WHERE rn <= 5
|
ORDER BY month ASC, avg_price DESC
|
||||||
ORDER BY month DESC, avg_price DESC
|
|
||||||
`,
|
`,
|
||||||
params: [params.roomType, params.startDate]
|
params: [params.roomType, params.startDate]
|
||||||
}),
|
};
|
||||||
|
},
|
||||||
|
|
||||||
// Filtered property queries (transactions with area + property type)
|
// Filtered property queries (transactions with area + property type)
|
||||||
filtered_transactions: (params) => ({
|
filtered_transactions: (params) => ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user