add get_ai_response
This commit is contained in:
2
.idea/RSI.iml
generated
2
.idea/RSI.iml
generated
@@ -19,7 +19,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/arma" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (rsi_env)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (rsi-env) (3)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -177,3 +177,77 @@ class SSLAdapter(HTTPAdapter):
|
||||
self.context = create_urllib3_context()
|
||||
self.context.options |= 0x4 # OP_LEGACY_SERVER_CONNECT
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def apply_date_filter(queryset, date_filter):
|
||||
if not date_filter:
|
||||
return queryset
|
||||
|
||||
field = date_filter.get("field", "Date")
|
||||
filter_type = date_filter.get("type")
|
||||
value = date_filter.get("value")
|
||||
|
||||
now = timezone.now()
|
||||
|
||||
if filter_type == "today":
|
||||
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end = start + timedelta(days=1)
|
||||
return queryset.filter(
|
||||
**{f"{field}__gte": start, f"{field}__lt": end}
|
||||
)
|
||||
|
||||
if filter_type == "yesterday":
|
||||
start = (now - timedelta(days=1)).replace(
|
||||
hour=0, minute=0, second=0, microsecond=0
|
||||
)
|
||||
end = start + timedelta(days=1)
|
||||
return queryset.filter(
|
||||
**{f"{field}__gte": start, f"{field}__lt": end}
|
||||
)
|
||||
|
||||
if filter_type == "last_n_days" and value:
|
||||
start = now - timedelta(days=int(value))
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
if filter_type == "this_week":
|
||||
start = now - timedelta(days=now.weekday())
|
||||
start = start.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
if filter_type == "this_month":
|
||||
start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
if filter_type == "last_n_month" and value:
|
||||
start = now
|
||||
for _ in range(int(value)):
|
||||
start = (start.replace(day=1) - timedelta(days=1)).replace(day=1)
|
||||
start = start.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
if filter_type == "this_year":
|
||||
start = now.replace(
|
||||
month=1, day=1, hour=0, minute=0, second=0, microsecond=0
|
||||
)
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
if filter_type == "last_n_year" and value:
|
||||
start = now.replace(
|
||||
year=now.year - int(value),
|
||||
month=1,
|
||||
day=1,
|
||||
hour=0,
|
||||
minute=0,
|
||||
second=0,
|
||||
microsecond=0
|
||||
)
|
||||
return queryset.filter(**{f"{field}__gte": start})
|
||||
|
||||
return queryset
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
app/migrations/__pycache__/0044_evacuationdetail.cpython-312.pyc
Normal file
BIN
app/migrations/__pycache__/0044_evacuationdetail.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
app/migrations/__pycache__/0046_rasadyarappinfo.cpython-312.pyc
Normal file
BIN
app/migrations/__pycache__/0046_rasadyarappinfo.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -11,9 +11,10 @@ from app.views import get_transport_to_kill, add_kill_house, update_hatching, ge
|
||||
dashboard_province_detail_for_map, TransportCarcassDashboardView, GuildsTransportCarcassDashboardView, \
|
||||
AllProductsTransportDashboardView, AllProductsTransportProductsListView, update_product_date, \
|
||||
send_transport_carcass_detail_for_rasadyaar, delete_free_bar_from_rasadyaar, fix_number, \
|
||||
get_evacuation_detail_by_request_code, get_evacuation_details_by_request_codes, evacuation_report_type_summary, get_all_products_transport_by_code, \
|
||||
get_evacuation_detail_by_request_code, get_evacuation_details_by_request_codes, evacuation_report_type_summary, \
|
||||
get_all_products_transport_by_code, \
|
||||
get_all_products_transport_dashboard_by_code, get_all_products_transport_products_by_code, \
|
||||
get_all_products_transport_provinces_by_code
|
||||
get_all_products_transport_provinces_by_code, get_ai_response
|
||||
|
||||
router = DefaultRouter()
|
||||
|
||||
@@ -236,6 +237,7 @@ urlpatterns = [
|
||||
path('get-all-products-transport-products-by-code/', get_all_products_transport_products_by_code),
|
||||
path('get-all-products-transport-provinces-by-code/', get_all_products_transport_provinces_by_code),
|
||||
path('all_products_transport_excel/', all_products_transport_excel),
|
||||
path('get_ai_response/', get_ai_response),
|
||||
|
||||
|
||||
]
|
||||
|
||||
55
app/views.py
55
app/views.py
@@ -26,7 +26,7 @@ from app.filtersets import PoultryFilterSet, PoultryHatchingFilterSet, Transport
|
||||
PoultryInfoFilterSet, HatchingCalculationsFilterSet, HatchingsFilterSet, TransportingDetailFilterSet, \
|
||||
KillHouseFilterSet, TransportingDetailCustomFilterSet, CustomHatchingsFilterSet, TransportCarcassDetailFilterSet, \
|
||||
DriverFilterSet, GuildsFilterSet, AllProductsTransportFilterSet
|
||||
from app.helper import SSLAdapter, get_hatching_permit_code, normalize_persian_arabic_text
|
||||
from app.helper import SSLAdapter, get_hatching_permit_code, normalize_persian_arabic_text, apply_date_filter
|
||||
from app.models import Poultry, PoultryHatching, TransportingChickenDetail, Hatching, TransportingDetail, KillHouse, \
|
||||
ApkInfo, TransportCarcassDetail, Guilds, Driver, InquiryCredentials, AllProductsTransport, EvacuationDetail, \
|
||||
RasadyarAppInfo
|
||||
@@ -5915,3 +5915,56 @@ def get_all_products_transport_dashboard_by_code(request):
|
||||
"total_output_bars_percent": output_percent,
|
||||
"total_output_bars_wight": int(output_quantity),
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@permission_classes([AllowAny])
|
||||
@csrf_exempt
|
||||
def get_ai_response(request):
|
||||
result_data = {}
|
||||
models_info = request.data.get('models_info')
|
||||
|
||||
for model_info in models_info:
|
||||
model_name = model_info.get("model")
|
||||
filters = model_info.get("filters", {})
|
||||
aggregations = model_info.get("aggregations") or []
|
||||
fields_to_return = model_info.get("fields_to_return") or []
|
||||
date_filter = model_info.get("date_filter")
|
||||
|
||||
if model_name == "Hatching":
|
||||
queryset = Hatching.objects.filter(**filters)
|
||||
|
||||
elif model_name == "Poultry":
|
||||
queryset = Poultry.objects.filter(**filters)
|
||||
|
||||
else:
|
||||
continue
|
||||
|
||||
queryset = apply_date_filter(queryset, date_filter)
|
||||
|
||||
model_result = {}
|
||||
|
||||
if "count" in aggregations:
|
||||
model_result["count"] = queryset.count()
|
||||
|
||||
if "sum" in aggregations:
|
||||
model_result["sum"] = (
|
||||
queryset.aggregate(total=Sum("ChickCountSum"))["total"] or 0
|
||||
)
|
||||
|
||||
if fields_to_return:
|
||||
descriptive_data = queryset.values(*fields_to_return).first()
|
||||
if descriptive_data:
|
||||
model_result.update(descriptive_data)
|
||||
|
||||
result_data[model_name] = model_result
|
||||
|
||||
return Response(
|
||||
{
|
||||
"data": result_data
|
||||
},
|
||||
status=status.HTTP_200_OK
|
||||
)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user