dimanche 9 juillet 2023

Center the text widget inside transform scale in Flutter

How can we edit the children of this widget in a widget that we use transform scale?

Expected

Code:

Transform.rotate(
              angle: math.pi / 4,
              child: Container(
                height: 100,
                width: 100,
                color: const Color(0xff565758),
                child: const Text("Lorem ipsum"),
              ),
            ),

Problem

Tried transform, transform.scale, FittedBox widgets. And the result is as in the picture above.

Solve:

Stack(
          children: [
            Transform.rotate(
              angle: math.pi / 4,
              child: Container(
                height: 100,
                width: 100,
                color: const Color(0xff565758),
              ),
            ),
            const Positioned.fill(child: Align(alignment: Alignment.center, child: Text("Lorem ipsum")))
          ],
        ),

samedi 8 juillet 2023

Which design pattern is best suited for approval process?

Which design pattern is best suited for approval process workflow? For example: A user raises a request for access to a particular application. The request has to go through 3 level of approvals L1, L2, L3. These approvals can be by a person/user or a group of users(i.e., group is an entity like SecurityGroup which has 4-5 members assigned). The design should be flexible enough to include another level of approval if required. Also, there can be scenarios where only L1 and L3 approval is required or only L2 and L3 approval is required. If you could provide a pseudo code that will be good.

Pattern API Gateway for MSA

We design our system based on micro service architecture. I have a question: how do I go from my backend_1 (InformationSystem_1) to the backend_2 (InformationSystem_1). Do I need to make a api gateway(API_outside on image) for communicating with external systems, or is it possible to go from backend_1 to backend_2 directly?There are no security requirements, but the backend_2 is done by another team. Which pattern is better to apply?

It seems to me that you need to make a separate service for going outside (API_outside) to hide all the insides of the backend. But how justified is this? enter image description here

vendredi 7 juillet 2023

swiftui: How to create custom shape?

This might not be the best post, with the most detail and the most programming related. But I hope you will give some pointers anyway.

I am specifically asking about the indents in the backgrounds. And even more so, how to layer the "tabs" on top of each other.

Thanks.

I am trying to create something like this:

jeudi 6 juillet 2023

Using a dictionary dispatch with a tuple - facing issues with args

from collections import defaultdict
#I have over 15 such functions
def sub_scenario_J_Conf(data):
    if data["cnt"] == "J" and data["data_class"].lower() == "conf":
        if data["cnt"] == "J" or data["person"] > 50 or data["person_no"] >= 500:
            return "A"
        elif data["cnt"] != "J" or data["person"] < 50 or data["person_no"] <= 500:
            return "B"
        else:
            return "F"
    else:
        return "Invalid option"

def sub_scenario_W_Conf_misdirected(data):
    if data["cnt"] == "W" and data["data_class"].lower() == "conf" and data.get("inc") == "diff":
        if data["person"] > 50 or data["person_no"] >= 500:
            return "A"
        elif data["person"] < 50 or data["person_no"] <= 500:
            return "B"
        else:
            return "F"
    else:
        return "Invalid option"

cases = defaultdict(lambda: lambda data: "Invalid option", {
    ("J", "Conf"): sub_scenario_J_Conf,
    ("W", "Conf", "diff"): sub_scenario_W_Conf_misdirected,
})

#fails here
data = {
    "cnt": "J",
    "data_class": "Conf",
    "person": 60,
    "person_no": 1000
}
#works here
data2 = {
    "cnt": "J",
    "data_class": "Conf",
     "data_diff":"diff",
    "person": 60,
    "person_no": 1000
}

sub_scenario_func = cases.get((data["cnt"], data["data_class"], data.get("inc", "")))
if sub_scenario_func:
    result = sub_scenario_func(data)
else:
    result = "Invalid option"

print(result)

data.get("inc", "") I am facing an issue with this, as it is unable to handle conditions where some functions take an input of two, while some take 3 or 4. How do I fix this? Also, if there is a better way to deal with the if conditions, do let me know, it would be of great help .

Feature grouping with NestJS

We are developing a multi-tenant application but I'm running into a situation where I need to use forwardRef quite often which would indicate a code smell as mentioned in the docs of NestJS. Example of modules in this applications are: app, auth, company, paymet, projectc, survey, search, tenant and user (there are more in reality).

Each module has their own service (aka provider), model, etc. We are using Prisma so we don't have a separate file for the typical crud methods and they are located inside the service itself.

Example of why forward ref is needed

Tenant module

@Module({
    imports: [PaymentModule],
    providers: [TenantService],
})
export class TenantModule {}

Tenant service

@Injectable()
export class TenantService {
    async get(tenantId: number) {
        return prisma.tenant.findFirst({ where: { id: tenantId } });
    }

    async create(data) {
        // ... logic
        const tenantId = generateId();
        await PaymentService.createCustomer(tenantId)
        // ... logic
    }
}

Payment module

@Module({
    imports: [TenantModule],
    providers: [PaymentService],
})
export class PaymentModule {}

Payment service

@Injectable()
export class PaymentService {
    async createCustomer(tenantId) {
        // ... logic
    }

    async charge(tenantId: number) {
        const tenant = await this.tenantService.get(tenantId);
        // ... logic
    }
}

Question

My question is how should we adjust our structure to be more "feature grouping". Currently for example we are using the tenant service in a lot of the other modules and I don't see how it would be a "feature". Any guidance, tips, links, documents that would help are highly welcome. I don't really see another way of doing this and can't find good examples either.

Extract pattern from Machine learning model

have created an ML model for a sports betting dataset, and its accuracy is 90%. The dataset contains the following column names:

python Copy code ['League', 'Time', 'Hour', 'Minute', 'TeamA', 'TeamB', 'Result', 'Result_FinalTime', 'Result_HalfTime', 'Odds', 'Odd', 'FirstTeamToScore', 'LastTeamToScore', 'Winner_HT_FT', 'Result_HalfTime_Odd', 'Id', 'timedelta', 'timestamp', 'Data', 'HomeTeamWin', 'AwayTeamWin', 'Day', 'BothTeamToScore', 'BothTeamToNotScore', 'BothTeamToScoreAndOver2.5', 'under_1_5', 'under_2_5', 'under_3_5', '2GoalsExactly', '3GoalsExactly', '5GoalsOrMore', 'BothTeamsToScoreHalfTime', 'Over1.5HalfTime', 'DrawFinalTime', 'HomeTeamWinsHalfTime', 'AwayTeamWinsHalfTime', '1-1FinalTime', 'DrawHalfTime', 'HomeTeamWin2-0', 'AwayTeamToScore', 'over_1_5', 'over_2_5', 'over_3_5', 'under_0_5', 'total_gols', 'ambas_marcam_odd', 'over_1_5_odds', 'over_2_5_odd', 'over_3_5_odd', 'Home', 'Away', 'team1_score', 'team2_score', 'y'] I want to create patterns based on the following conditions:

Over 3.5 (more than 3 goals):

Sample: 3404 Successful: 764 Unsuccessful: 2640 Martingale needed: 2 times (Maximum 2) Success rate: 22.444183313748532% Description: After a match with more than 3 goals, place a bet on Over 3.5 goals. Under 1.5 (1 or fewer goals):

Sample: 3404 Successful: 754 Unsuccessful: 2650 Martingale needed: 2 times (Maximum 2) Success rate: 22.150411280846065% Description: After a match with 1 or fewer goals, place a bet on Under 1.5 goals. Under 2.5 (2 or fewer goals):

Sample: 3404 Successful: 1669 Unsuccessful: 1735 Martingale needed: 2 times (Maximum 2) Success rate: 49.030552291421856% Description: After a match with 2 or fewer goals, place a bet on Under 2.5 goals. Martingale can be from 0-2. I have prepared the feature matrix X and the target variable y as follows:

python Copy code import pandas as pd from sklearn.model_selection import train_test_split

Prepare the feature matrix X and the target variable y

X = data[['League', 'Hour', 'Minute', 'HomeTeamWin', 'AwayTeamWin', 'over_1_5', 'over_2_5', 'over_3_5', 'under_1_5', 'under_2_5', 'under_3_5']] # Adjust the column names as per your dataset y = data['y']

Split the dataset into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Initialize the XGBoost classifier

model = XGBClassifier() # Replace with the appropriate classifier

Fit the model on the training data

model.fit(X_train, y_train)

Evaluate the model on the training set

train_success_rate = model.score(X_train, y_train) * 100

Evaluate the model on the test set

test_success_rate = model.score(X_test, y_test) * 100

print(f"Training Success rate: {train_success_rate}%") print(f"Test Success rate: {test_success_rate}%")

I want to find patterns in the dataset using this model. Can anyone please help me with this?


python Copy code ['League', 'Time', 'Hour', 'Minute', 'TeamA', 'TeamB', 'Result', 'Result_FinalTime', 'Result_HalfTime', 'Odds', 'Odd', 'FirstTeamToScore', 'LastTeamToScore', 'Winner_HT_FT', 'Result_HalfTime_Odd', 'Id', 'timedelta', 'timestamp', 'Data', 'HomeTeamWin', 'AwayTeamWin', 'Day', 'BothTeamToScore', 'BothTeamToNotScore', 'BothTeamToScoreAndOver2.5', 'under_1_5', 'under_2_5', 'under_3_5', '2GoalsExactly', '3GoalsExactly', '5GoalsOrMore', 'BothTeamsToScoreHalfTime', 'Over1.5HalfTime', 'DrawFinalTime', 'HomeTeamWinsHalfTime', 'AwayTeamWinsHalfTime', '1-1FinalTime', 'DrawHalfTime', 'HomeTeamWin2-0', 'AwayTeamToScore', 'over_1_5', 'over_2_5', 'over_3_5', 'under_0_5', 'total_gols', 'ambas_marcam_odd', 'over_1_5_odds', 'over_2_5_odd', 'over_3_5_odd', 'Home', 'Away', 'team1_score', 'team2_score', 'y'] I want to create patterns based on the following conditions:

Over 3.5 (more than 3 goals):

Sample: 3404 Successful: 764 Unsuccessful: 2640 Martingale needed: 2 times (Maximum 2) Success rate: 22.444183313748532% Description: After a match with more than 3 goals, place a bet on Over 3.5 goals. Under 1.5 (1 or fewer goals):

Sample: 3404 Successful: 754 Unsuccessful: 2650 Martingale needed: 2 times (Maximum 2) Success rate: 22.150411280846065% Description: After a match with 1 or fewer goals, place a bet on Under 1.5 goals. Under 2.5 (2 or fewer goals):

Sample: 3404 Successful: 1669 Unsuccessful: 1735 Martingale needed: 2 times (Maximum 2) Success rate: 49.030552291421856% Description: After a match with 2 or fewer goals, place a bet on Under 2.5 goals. Martingale can be from 0-2. I have prepared the feature matrix X and the target variable y as follows:

python Copy code import pandas as pd from sklearn.model_selection import train_test_split

Prepare the feature matrix X and the target variable y

X = data[['League', 'Hour', 'Minute', 'HomeTeamWin', 'AwayTeamWin', 'over_1_5', 'over_2_5', 'over_3_5', 'under_1_5', 'under_2_5', 'under_3_5']] # Adjust the column names as per your dataset y = data['y']

Split the dataset into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Initialize the XGBoost classifier

model = XGBClassifier() # Replace with the appropriate classifier

Fit the model on the training data

model.fit(X_train, y_train)

Evaluate the model on the training set

train_success_rate = model.score(X_train, y_train) * 100

Evaluate the model on the test set

test_success_rate = model.score(X_test, y_test) * 100

print(f"Training Success rate: {train_success_rate}%") print(f"Test Success rate: {test_success_rate}%")

I want to find patterns in the dataset using this model. Can anyone please help me with this?