优化计算方式

This commit is contained in:
沈健
2025-03-07 15:55:10 +08:00
parent 079652a557
commit 5f9c42623c
+13 -3
View File
@@ -33,9 +33,11 @@ def calc(city, year_month):
if pd.notna(year_month):
last_year_month = dateutils.format_date(
dateutils.add_months(dateutils.parse_date(str(year_month), '%Y%m'), months=-13), '%Y%m')
last_month = dateutils.format_date(dateutils.add_months(dateutils.parse_date(str(year_month), '%Y%m'), months=-1), '%Y%m')
sql += "and p_date >= '" + last_year_month + "01' "
else:
last_year_month = dateutils.format_date(dateutils.add_months(datetime.now(), months=-13), '%Y%m')
last_month = dateutils.format_date(dateutils.add_months(datetime.now(), months=-1), '%Y%m')
sql += "and p_date >= '" + last_year_month + "01' "
date = dateutils.add_months(datetime.today(), months=-1)
year_month = int(dateutils.format_date(date, '%Y%m'))
@@ -126,7 +128,8 @@ def calc(city, year_month):
'$match': {
'estate_type2': estate_type2,
'bed_kind': bed_kind,
'calc_type': 1
'calc_type': 1,
'date': year_month
}
},
{
@@ -184,7 +187,8 @@ def calc(city, year_month):
},
{
'$match': {
'estate_type2': estate_type2
'estate_type2': estate_type2,
'date': year_month
}
},
{
@@ -222,7 +226,8 @@ def calc(city, year_month):
},
{
'$match': {
'bed_kind': bed_kind
'bed_kind': bed_kind,
'date': year_month
}
},
{
@@ -283,6 +288,11 @@ def calc(city, year_month):
'spherical': True
}
},
{
'$match': {
'date': year_month
}
},
{
'$limit': 5
}