Skip to content

Commit 4f826d3

Browse files
gdgs, gramin, changes in niti
Niti changes made to daily farmer and farmer linelist. once tested, changes to be incorporated in gdgs and gramin
1 parent cdd6a72 commit 4f826d3

68 files changed

Lines changed: 4092 additions & 55 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,57 @@ dbt_atcef
2626
│ ├─ .gitkeep
2727
│ └─ generate_schema_name.sql
2828
├─ models
29+
├── analytics
30+
│   │   └── niti_2025
31+
│   │   ├── encounters
32+
│   │   │   ├── farmer_endline_niti_25.sql
33+
│   │   │   ├── gp_endline_niti_25.sql
34+
│   │   │   ├── machine_endline_niti_25.sql
35+
│   │   │   ├── work_order_endline_niti_25.sql
36+
│   │   │   ├── work_order_farmer_niti_25.sql
37+
│   │   │   └── work_order_machine_niti_25.sql
38+
│   │   ├── registrations
39+
│   │   │   ├── farmer_regn_niti_25.sql
40+
│   │   │   ├── gp_regn_niti_25.sql
41+
│   │   │   ├── machine_regn_niti_25.sql
42+
│   │   │   └── work_order_regn_niti_25.sql
43+
│   │   ├── reports
44+
│   │   │   ├── aggregated
45+
│   │   │   │   ├── dam_wise_farmer_niti_25.sql
46+
│   │   │   │   ├── dam_wise_work_order_niti_25.sql
47+
│   │   │   │   ├── org_level_niti_25.sql
48+
│   │   │   │   ├── overall_approval_statistics_niti_25.sql
49+
│   │   │   │   ├── work_order_aggregate_dam_niti_25.sql
50+
│   │   │   │   └── work_order_aggregate_org_niti_25.sql
51+
│   │   │   ├── cleaned
52+
│   │   │   │   ├── active_work_order_niti_25.sql
53+
│   │   │   │   ├── daily_farmer_linelist_niti_25.sql
54+
│   │   │   │   ├── daily_machine_linelist_niti_25.sql
55+
│   │   │   │   ├── farmer_endline_linelist_niti_25.sql
56+
│   │   │   │   ├── farmer_linelist_niti_25.sql
57+
│   │   │   │   ├── machine_endline_linelist_niti_25.sql
58+
│   │   │   │   ├── machine_linelist_niti_25.sql
59+
│   │   │   │   ├── waterbody_linelist_niti_25.sql
60+
│   │   │   │   ├── workorder_endline_linelist_niti_25.sql
61+
│   │   │   │   └── workorder_linelist_niti_25.sql
62+
│   │   │   └── status
63+
│   │   │   ├── daily_farmer_linelist_approval_niti_25.sql
64+
│   │   │   ├── daily_machine_linelist_approval_niti_25.sql
65+
│   │   │   ├── farmer_endline_linelist_approval_niti_25.sql
66+
│   │   │   ├── farmer_linelist_approval_niti_25.sql
67+
│   │   │   ├── gp_linelist_approval_niti_25.sql
68+
│   │   │   ├── machine_endline_linelist_approval_niti_25.sql
69+
│   │   │   ├── machine_linelist_approval_niti_25.sql
70+
│   │   │   ├── workorder_endline_linelist_approval_niti_25.sql
71+
│   │   │   └── workorder_linelist_approval_niti_25.sql
72+
│   │   └── source
73+
│   │   ├── approval_status_niti_25.sql
74+
│   │   ├── dim_subjects_farmer_niti_25.sql
75+
│   │   ├── dim_subjects_gp_niti_25.sql
76+
│   │   ├── dim_subjects_machine_niti_25.sql
77+
│   │   ├── dim_subjects_work_order_niti_25.sql
78+
│   │   ├── encounter_type_niti_25.sql
79+
│   │   └── location_niti_25.sql
2980
│ ├─ intermediate
3081
│ │ ├─ avni_gdgsgom_2023
3182
│ │ │ ├─ approval_statuses_gdgs_2023.sql
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- contains information from the encounters staging table filtered for "Farmer Endline"
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics", "gdgs_2025", "gdgs", "analytics_intermediate", "analytics_encounters_gdgs_25"]
5+
) }}
6+
7+
SELECT
8+
e.eid,
9+
e.subject_id as endline_farmer_sub_id,
10+
e.encounter_type,
11+
e.subject_type,
12+
e.encounter_date_time,
13+
CAST(e.observations ->> 'Land holding (acres)' AS NUMERIC) AS land_holding,
14+
CAST(e.observations ->> 'Total silt excavated' AS NUMERIC) AS total_silt_excavated,
15+
e.observations ->> 'Distance from waterbody' AS distance_from_waterbody,
16+
e.observations ->> 'Major crops grown on the land' AS major_crops_grown,
17+
e.observations ->> 'Type of land silt is spread on' AS type_of_land_silt_is_spread_on,
18+
e.observations ->> 'Category of farmer - Farmer Endline' AS farmer_category,
19+
CAST(e.observations ->> 'The total farm area on which Silt is spread' AS NUMERIC) AS area_silt_spread,
20+
e.observations ->> 'MGNREGA card number or any other ID card number' AS mgnrega_card_number,
21+
CAST(e.observations ->> 'Total cost borne by the farmer for carting silt (INR)' AS NUMERIC) AS total_carting_cost,
22+
e.observations ->> 'Major crops to be grown on the land where silt is spread' AS major_to_be_grown,
23+
e.observations ->> 'Is the land-holding information correct? - Farmer Endline' AS land_holding_info_correct,
24+
CAST(e.observations ->> 'Total cost borne by the farmer for spreading/levelling silt on farm (INR)' AS NUMERIC) AS total_spreading_cost,
25+
e.voided
26+
27+
FROM {{ ref('encounter_type_gdgs_25') }} e
28+
WHERE e.encounter_type = 'Farmer Endline'
29+
-- and e.voided = false
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- contains information from the encounters staging table filtered for "Excavating Machine Endline"
2+
3+
{{ config(
4+
materialized='table',
5+
tags=["analytics", "gdgs_2025", "gdgs", "analytics_intermediate", "analytics_encounters_gdgs_25"]
6+
) }}
7+
8+
SELECT
9+
e.eid,
10+
e.subject_id as endline_machine_sub_id,
11+
e.encounter_type,
12+
e.subject_type,
13+
e.encounter_date_time,
14+
e.observations ->> 'NGO Name' AS ngo_name,
15+
CAST(e.observations ->> 'Total working hours of machine' AS NUMERIC) AS total_machine_working_hours,
16+
e.voided
17+
18+
FROM {{ ref('encounter_type_gdgs_25') }} e
19+
WHERE e.encounter_type = 'Excavating Machine Endline'
20+
-- and e.voided = false
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- contains information from the encounters staging table filtered for "Work order endline"
2+
3+
{{ config(
4+
materialized='table',
5+
tags=["analytics", "gdgs_2025", "gdgs", "analytics_intermediate", "analytics_encounters_gdgs_25"]
6+
) }}
7+
8+
SELECT
9+
e.eid,
10+
e.subject_id as endline_work_order_sub_id,
11+
e.encounter_type,
12+
e.subject_type,
13+
e.encounter_date_time,
14+
e.observations ->> 'NGO Name' AS ngo,
15+
e.observations ->> 'Video of Site' AS site_video,
16+
e.observations ->> 'MB Recording done' AS mb_recording_done,
17+
e.observations ->> 'Image 1 of the site' AS site_image_1_url,
18+
e.observations ->> 'Image 2 of the site' AS site_image_2_url,
19+
CAST(e.observations ->> 'Total silt excavated' AS NUMERIC) AS total_silt_excavated,
20+
e.observations ->> 'Document of MB recording' AS mb_document_url,
21+
CAST(e.observations ->> 'Silt excavated as per MB recording' AS NUMERIC) AS silt_excavated_as_per_mb,
22+
e.observations ->> 'Is MB recording data same as app data?' AS is_mb_data_same_as_app_data,
23+
e.voided
24+
25+
FROM {{ ref('encounter_type_gdgs_25') }} e
26+
WHERE e.encounter_type = 'Work order endline'
27+
-- and e.voided = false
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- contains information from the encounters staging table filtered for "Work order daily Recording - Farmer"
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics", "gdgs_2025", "gdgs", "analytics_intermediate", "analytics_encounters_gdgs_25"]
5+
) }}
6+
7+
SELECT
8+
e.eid,
9+
e.subject_id as farmer_work_order_sub_id,
10+
e.encounter_type,
11+
e.subject_type,
12+
e.encounter_date_time,
13+
CAST(e.observations ->> 'Total Silt carted' AS NUMERIC) AS silt_carted,
14+
e.observations ->> 'Excavating Machine' AS machine_sub_id,
15+
e.observations ->> 'Farmer/Beneficiary' AS farmer_beneficiary_id,
16+
CAST(e.observations ->> 'Number of trolleys carted' AS NUMERIC) AS trolleys_carted,
17+
CAST(e.observations ->> 'Capacity of trolleys in cu.m.' AS NUMERIC) AS capacity_trolleys,
18+
CAST(e.observations ->> 'Number of hyvas/dumper carted' AS NUMERIC) AS hyvas_carted,
19+
e.observations ->> 'The silt has been used for non-farm purpose' AS if_silt_used_non_farm_purpose,
20+
REPLACE(
21+
REPLACE(
22+
REPLACE(
23+
e.observations ->> 'Purpose of carting silt',
24+
'[', ''
25+
),
26+
']', ''
27+
),
28+
'"', ''
29+
) AS purpose_of_carting_silt,
30+
CAST(e.observations ->> 'How much silt has been used for non-farm purpose' AS NUMERIC) AS amt_silt_used_non_farm_purpose,
31+
e.voided,
32+
33+
e.observations ->> 'Silt taken by' AS silt_taken_by, -- new
34+
e.observations ->> 'Other person taking silt' AS other_person_taking_silt, -- new
35+
e.observations ->> 'Other purpose of carting silt' AS other_purpose_of_carting_silt -- new
36+
37+
FROM {{ ref('encounter_type_gdgs_25') }} e
38+
WHERE e.encounter_type = 'Work order daily Recording - Farmer'
39+
-- and e.voided = false
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- contains information from the encounters staging table filtered for "Work order daily Recording - Machine"
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics", "gdgs_2025", "gdgs", "analytics_intermediate", "analytics_encounters_gdgs_25"]
5+
) }}
6+
7+
SELECT
8+
e.eid,
9+
e.subject_id as machine_work_order_sub_id,
10+
e.encounter_type,
11+
e.subject_type,
12+
e.encounter_date_time,
13+
e.observations ->> 'Log book image 1' AS log_book_image_machine,
14+
e.observations ->> 'Excavating Machine' AS excavating_machine_id,
15+
CAST(e.observations ->> 'Total working hours' AS NUMERIC) AS total_working_hours,
16+
CAST(e.observations ->> 'Working Hours as per time' AS NUMERIC) AS working_hours,
17+
e.voided
18+
FROM {{ ref('encounter_type_gdgs_25') }} e
19+
WHERE e.encounter_type = 'Work order daily Recording - Machine'
20+
-- and e.voided = false
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- Farmer registration mart combining subject, location, and approval details for gdgs 2025.
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics","analytics_gdgs_2025", "registrations_gdgs_2025"]
5+
) }}
6+
7+
with farmer_data as (
8+
SELECT
9+
f.*,
10+
l.*,
11+
a.approval_status
12+
13+
FROM
14+
{{ ref('dim_subjects_farmer_gdgs_25') }} AS f
15+
LEFT JOIN
16+
{{ ref('location_gdgs_25') }} AS l
17+
ON f.location_id = l.address_id
18+
LEFT JOIN
19+
{{ ref('approval_status_gdgs_25') }} AS a
20+
ON f.subject_id = a.entity_id
21+
22+
WHERE f.voided != TRUE)
23+
24+
select
25+
subject_id,
26+
registration_date,
27+
farmer_first_name as farmer_name,
28+
land_holding_acres as land_holding,
29+
mobile_number,
30+
mobile_verified_status,
31+
farmer_category,
32+
total_silt_required,
33+
number_hywas_required,
34+
number_trolleys_required,
35+
capacity_trolleys_cum,
36+
farmer_contribution_per_trolley,
37+
silt_target,
38+
state,
39+
district,
40+
taluka,
41+
village,
42+
dam,
43+
gram_panchayat_name as gp,
44+
stakeholder_responsible,
45+
approval_status
46+
from farmer_data
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- Machine registration table with cleaned identifiers, location, and approval metadata for gdgs 2025.
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics","analytics_gdgs_2025", "registrations_gdgs_2025"]
5+
) }}
6+
7+
SELECT
8+
m.subject_id,
9+
m.registration_date,
10+
m.subject_type,
11+
m.location_id,
12+
-- m.ngo_name as stakeholder_responsible,
13+
UPPER(REPLACE(REPLACE(REGEXP_REPLACE(
14+
COALESCE(m.machine_name::TEXT, ''), -- 1. Cast to TEXT for string operations
15+
'[-\s]+', -- 2. Target ONE OR MORE hyphens (-) or whitespace characters (\s)
16+
'',
17+
'g'
18+
),CHR(9),
19+
''),CHR(160),''))::VARCHAR AS machine_name,
20+
m.machine_type,
21+
m.contractor_name,
22+
m.contractor_mobile_number,
23+
m.voided,
24+
l.*,
25+
a.approval_status,
26+
a.status_date_time as approval_date_time
27+
28+
29+
FROM
30+
{{ ref('dim_subjects_machine_gdgs_25') }} AS m
31+
LEFT JOIN
32+
{{ ref('location_gdgs_25') }} AS l
33+
ON m.location_id = l.address_id
34+
LEFT JOIN
35+
{{ ref('approval_status_gdgs_25') }} AS a
36+
ON m.subject_id = a.entity_id
37+
38+
WHERE m.voided != TRUE
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Work order registration detail table pairing subject attributes with location and approval data for gdgs 2025.
2+
{{ config(
3+
materialized='table',
4+
tags=["analytics","analytics_gdgs_2025", "registrations_gdgs_2025"]
5+
) }}
6+
7+
SELECT
8+
w.*,
9+
-- we.encounter_date_time as endline_date,
10+
l.*,
11+
a.approval_status
12+
13+
FROM
14+
{{ ref('dim_subjects_work_order_gdgs_25') }} AS w
15+
LEFT JOIN
16+
{{ ref('location_gdgs_25') }} AS l
17+
ON w.location_id = l.address_id
18+
LEFT JOIN
19+
{{ ref('approval_status_gdgs_25') }} AS a
20+
ON w.subject_id = a.entity_id
21+
22+
WHERE w.voided != TRUE
23+
24+

0 commit comments

Comments
 (0)