Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
improve sample data generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremi committed Feb 2, 2024
1 parent 32a89df commit 55bdec0
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions spp_farmer_registry_demo/models/generate_farmer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,51 @@ def _generate_sample_data(self, **kwargs):
land_record_id = res._generate_land_record_record(group_id)
group_id.farm_land_rec_id = land_record_id.id

crop_farm_species_id = res._get_species_data(species_type="crop")
live_farm_species_id = res._get_species_data()
aqua_farm_species_id = res._get_species_data(species_type="aquaculture")

crop_farm_activity_id = res._generate_agricultural_activity_data(
activity_type="crop",
crop_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=crop_farm_species_id.id,
)

live_farm_activity_id = res._generate_agricultural_activity_data(
activity_type="livestock",
live_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=live_farm_species_id.id,
)

aqua_farm_activity_id = res._generate_agricultural_activity_data(
activity_type="aquaculture",
aqua_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=aqua_farm_species_id.id,
)
# create a random number of agricultural activities
for _ in range(random.randint(1, 5)):
crop_farm_species_id = res._get_species_data(species_type="crop")
live_farm_species_id = res._get_species_data()
aqua_farm_species_id = res._get_species_data(species_type="aquaculture")

res._generate_agricultural_activity_data(
activity_type="crop",
crop_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=crop_farm_species_id.id,
)

res._generate_agricultural_activity_data(
activity_type="livestock",
live_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=live_farm_species_id.id,
)

res._generate_agricultural_activity_data(
activity_type="aquaculture",
aqua_farm_id=group_id.id,
land_id=land_record_id.id,
species_id=aqua_farm_species_id.id,
)

farm_details_data = res._generate_farm_details_data()
group_id.farm_detail_id.write(farm_details_data)

asset_type_id = res._get_asset_type_data()
machinery_type_id = res._get_machinery_type_data()

farm_asset_id = res._generate_farm_asset_data(
asset_farm_id=group_id.id,
land_id=land_record_id.id,
asset_type_id=asset_type_id.id,
)

farm_machinery_id = res._generate_farm_asset_data(
machinery_farm_id=group_id.id,
land_id=land_record_id.id,
machinery_type_id=machinery_type_id.id,
)
for _ in range(random.randint(3, 7)):
asset_type_id = res._get_asset_type_data()
machinery_type_id = res._get_machinery_type_data()

res._generate_farm_asset_data(
asset_farm_id=group_id.id,
land_id=land_record_id.id,
asset_type_id=asset_type_id.id,
)

res._generate_farm_asset_data(
machinery_farm_id=group_id.id,
land_id=land_record_id.id,
machinery_type_id=machinery_type_id.id,
)

if res.state == "draft":
res.update({"state": "generate"})
Expand Down

0 comments on commit 55bdec0

Please sign in to comment.