This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prorate_proportionally(df: pd.DataFrame, group: pd.DataFrame): | |
| # Get the total tonnage values from the first row | |
| total_tonnage_moved_contract = group.iloc[0]["tonnage_moved_contract"] | |
| total_tonnage_moved_spot = group.iloc[0]["tonnage_moved_spot"] | |
| total_tonnage_moved_unknown = group.iloc[0]["tonnage_moved_unknown"] | |
| # Calculate the total commitment | |
| total_commitment = group["tonnage_committed"].sum() | |
| # Compute proration factors for each row |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import msal | |
| import httpx | |
| from dynaconf import Dynaconf | |
| # Load configuration | |
| config = Dynaconf( | |
| settings_files=['settings.toml', '.secrets.toml'], | |
| environments=True, | |
| load_dotenv=True, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import pyodbc | |
| import re | |
| from datetime import date, datetime | |
| from typing import Any, Dict, Optional, List | |
| def load_json(file_path: str) -> Any: | |
| with open(file_path, 'r') as file: | |
| return json.load(file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import json | |
| def run_powershell_command(command): | |
| completed_process = subprocess.run( | |
| ["powershell", "-Command", command], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if completed_process.returncode != 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import logging | |
| import os | |
| from typing import Any, Dict, Optional, Type, List, Tuple | |
| import jsonref # Library for resolving JSON schema references | |
| from jsonschema import Draft7Validator | |
| from sqlalchemy import ( | |
| JSON, | |
| Boolean, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import uuid | |
| from sqlalchemy import create_engine, Column, Integer, String, Float, Boolean, DateTime, ForeignKey | |
| from sqlalchemy.orm import declarative_base, sessionmaker, relationship | |
| from sqlalchemy.dialects.mssql import UNIQUEIDENTIFIER | |
| from datetime import datetime | |
| Base = declarative_base() | |
| class Product(Base): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import re | |
| def convert_json_schema_to_sql(schema: dict[str, any]) -> list[str]: | |
| tables = [] | |
| foreign_keys = [] | |
| indexes = [] | |
| definitions = schema.get('definitions', {}) | |
| # Handle top-level properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from pathlib import Path | |
| from genson import SchemaBuilder | |
| def generate_schema_from_files(directory): | |
| builder = SchemaBuilder() | |
| directory_path = Path(directory) | |
| for file_path in directory_path.glob('*.json'): | |
| with file_path.open('r') as f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| t.Category, | |
| MIN(j.eventRecordedTime) AS MinEventTime, | |
| MAX(j.eventRecordedTime) AS MaxEventTime, | |
| AVG(j.someNumericValue) AS AvgValue | |
| FROM | |
| t | |
| CROSS APPLY OPENJSON(CAST(CAST(t.message AS varchar(max)) AS nvarchar(max))) | |
| WITH ( | |
| eventRecordedTime datetime2 '$.eventRecordedTime', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Use explicit comparison in aggregation: | |
| #Let's try using the aggregation framework with explicit type checking: | |
| rom bson import Int64 | |
| pipeline = [ | |
| { | |
| "$match": { | |
| "$expr": { | |
| "$and": [ |