Skip to content

Commit

Permalink
fix examples in/out
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Dec 24, 2024
1 parent 9f87a3c commit 33ce3e4
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 92 deletions.
5 changes: 5 additions & 0 deletions app/server/api/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
@router.post("/", response_model=LocationOut, response_description="Location data created")
async def create_location(location: LocationIn):
logger.info(f"POST {PATH_PREFIX} {location}")

document = location.toMongoDict()
document['openstreetmap'] = f'https://www.openstreetmap.org/#map=14/{location.latitude}/{location.longitude}'
location = LocationOut.fromMongoDict(document)

return create_in_collection(location, LocationOut)


Expand Down
11 changes: 6 additions & 5 deletions app/server/model/config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from datetime import datetime

from copy import deepcopy
from pydantic import BaseModel, field_validator, Field
from server.error import raise_with_log
from server.mongo import MongoModel

EXAMPLE_IN = {
"name": "MainSeasons2024",
"startOfSeason": "2024-08-01",
"endOfSeason": "2024-12-31"
"name": "2025 First Seasons",
"startOfSeason": "2025-01-15",
"endOfSeason": "2025-06-30"
}

EXAMPLE_OUT = EXAMPLE_IN
EXAMPLE_OUT = deepcopy(EXAMPLE_IN)
EXAMPLE_OUT["_id"] = "7Zv4TZoBLxUi"
EXAMPLE_OUT["year"] = 2014
EXAMPLE_OUT["year"] = 2025
EXAMPLE_OUT["seasonDays"] = 120

class ConfigIn(MongoModel):
Expand Down
9 changes: 4 additions & 5 deletions app/server/model/location.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import iso3166

from copy import deepcopy
from pydantic import field_validator, Field
from server.error import raise_with_log
from server.mongo import MongoModel
Expand All @@ -12,13 +13,12 @@
"village": "Kiziba",
"latitude": -0.4365,
"longitude": 31.6780,
"openstreetmap": "https://www.openstreetmap.org/#map=14/-0.4365/31.6780",
"coordinatesLevel": "VILLAGE",
"onchainId": ""
}

EXAMPLE_OUT = EXAMPLE_IN
EXAMPLE_OUT = deepcopy(EXAMPLE_IN)
EXAMPLE_OUT["_id"] = "kDho7606IRdr"
EXAMPLE_OUT["openstreetmap"] = "https://www.openstreetmap.org/#map=14/-0.4365/31.6780",

class LocationIn(MongoModel):
country: str
Expand All @@ -28,9 +28,7 @@ class LocationIn(MongoModel):
village: str
latitude: float
longitude: float
openstreetmap: str
coordinatesLevel: str
onchainId: str = Field(default=None)

@field_validator('country')
@classmethod
Expand All @@ -51,6 +49,7 @@ class Config:

class LocationOut(LocationIn):
_id: str
openstreetmap: str| None = Field(default=None)
id: str = Field(default=None)
tx: str | None = Field(default=None)

Expand Down
53 changes: 0 additions & 53 deletions app/server/model/onchain.py

This file was deleted.

6 changes: 4 additions & 2 deletions app/server/model/person.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from copy import deepcopy
from pydantic import field_validator, Field

from server.error import raise_with_log
from server.mongo import MongoModel
from util.nanoid import is_valid_nanoid
from web3utils.wallet import Wallet
from util.nanoid import is_valid_nanoid

EXAMPLE_IN = {
"locationId": "U6ufadiIe0Xz",
Expand All @@ -13,7 +15,7 @@
"mobilePhone": "+25656234567",
}

EXAMPLE_OUT = EXAMPLE_IN
EXAMPLE_OUT = deepcopy(EXAMPLE_IN)
EXAMPLE_OUT["id"] = "fXJ6Gwfgnw-C"
EXAMPLE_OUT["walletIndex"] = 2345,
EXAMPLE_OUT["wallet"] = "0x03507c8a16513F1615bD4a00BDD4570514a6ef21"
Expand Down
8 changes: 5 additions & 3 deletions app/server/model/policy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from copy import deepcopy
from pydantic import field_validator, Field

from server.error import raise_with_log
from server.mongo import MongoModel
from util.date import Date
Expand All @@ -8,20 +10,20 @@
"personId": "fXJ6Gwfgnw-C",
"riskId": "t4FcP75uGHHc",
"externalId": "ABC123",
"subscriptionDate": "2024-06-14",
"subscriptionDate": "2025-01-01",
"sumInsuredAmount": 1000000.0,
"premiumAmount": 200000.0,
}

EXAMPLE_OUT = EXAMPLE_IN
EXAMPLE_OUT = deepcopy(EXAMPLE_IN)
EXAMPLE_OUT["id"] = "cwNCXQfypiTg"
EXAMPLE_OUT["nft"] = "2689313703"

# https://www.xe.com/currencyconverter/convert/?Amount=300&From=USD&To=UGX
MAX_MONETARY_AMOUNT = 5000000.0

MIN_DATE = Date.create_from("2024-01-01")
MAX_DATE = Date.create_from("2024-12-31")
MAX_DATE = Date.create_from("2025-12-31")

class PolicyIn(MongoModel):
personId: str
Expand Down
28 changes: 9 additions & 19 deletions app/server/model/risk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pydantic import field_validator, Field, BaseModel

from server.config import settings
Expand Down Expand Up @@ -28,25 +29,14 @@
"finalPayout": 0.27
}


EXAMPLE_OUT = {
"id": "jxmbyupsh1rv",
"isValid": True,
"configId": "7Zv4TZoBLxUi",
"locationId": "kDho7606IRdr",
"crop": "coffee",
"startOfSeason": "2024-08-01",
"endOfSeason": "2024-11-30",
"deductible": 0.0,
"draughtLoss": 0.27,
"excessRainfallLoss": 0.05,
"totalLoss": 0.27,
"payout": 0.27,
"finalPayout": 0.27,
"onchainId": "2689313703",
"createdAt": 1700316957,
"updatedAt": 1700316957
}
EXAMPLE_OUT = deepcopy(EXAMPLE_IN)
EXAMPLE_OUT["draughtLoss"] = 0.27
EXAMPLE_OUT["excessRainfallLoss"] = 0.05
EXAMPLE_OUT["totalLoss"] = 0.27
EXAMPLE_OUT["payout"] = 0.27
EXAMPLE_OUT["finalPayout"] = 0.27
EXAMPLE_OUT["createdAt"] = 1700316957
EXAMPLE_OUT["updatedAt"] = 1700316957

class RiskIn(BaseModel):
isValid: bool
Expand Down
1 change: 0 additions & 1 deletion app/server/sync/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def sync_policy_onchain(policy: PolicyOut, force: bool = False):
sum_insured = int(policy.sumInsuredAmount)
premium = int(policy.premiumAmount)

activate_at = int()
tx = product.createPolicy(policy_holder, risk_id, activate_at, sum_insured, premium, {'from': operator})

logger.info(f"{tx} onchain policy {policy.id} created")
Expand Down
5 changes: 1 addition & 4 deletions app/web3utils/contract.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import json
from typing import Any, Dict
from util.logging import get_logger
from loguru import logger

from web3 import Web3
from web3.contract import Contract as Web3Contract
from web3.exceptions import TimeExhausted
from web3.types import FilterParams
from web3utils.wallet import Wallet

# setup for module
logger = get_logger()

class Contract:

FOUNDRY_OUT = "../out"
Expand Down

0 comments on commit 33ce3e4

Please sign in to comment.