Skip to content

Typescript #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
03607ea
Merge pull request #20 from maxvonhippel/first-example-v21
maxvonhippel Aug 15, 2024
786c5d8
Update README.md
maxvonhippel Aug 15, 2024
76d48e1
triggering pull request
Aug 23, 2024
34c3418
add leetcode example with edit distance
maxvonhippel Aug 30, 2024
8224746
saving new logic
maxvonhippel Sep 1, 2024
0eb7d00
Merge branch 'main' of github.com:maxvonhippel/benchify-examples
maxvonhippel Sep 1, 2024
94332fb
trigger leetcode run
maxvonhippel Sep 1, 2024
c1d762b
Fix the error to be better
maxvonhippel Sep 1, 2024
907efc0
improved comment for better demo
maxvonhippel Sep 2, 2024
5c867e6
improved comment
maxvonhippel Sep 2, 2024
fe1498f
Remove LeetCode stuff for better diff
Sep 3, 2024
8772827
Fix gitignore so we dont accidentally push pytest stuff
Sep 3, 2024
9bbaabc
reduce the requirements for rapid prototyping
maxvonhippel Sep 3, 2024
1de770f
add minDistance
maxvonhippel Sep 3, 2024
85ad601
Wrote commit with aws mocks ... first test run now
maxvonhippel Sep 20, 2024
e1e2407
improve aws test
maxvonhippel Sep 21, 2024
6e6266b
Fix utc now thing for demo
maxvonhippel Sep 21, 2024
6d990e6
Delete bad requirement and add some newlines ins cript
maxvonhippel Sep 22, 2024
6e8215a
Clean up script again to fix log calling for cloudwatch demo, add new…
maxvonhippel Sep 22, 2024
9ed8e43
initial version of redis mocking test
maxvonhippel Sep 22, 2024
bdf5852
Add READMEs for LeetCode and Redis
maxvonhippel Sep 23, 2024
d86f787
improve READMEs
maxvonhippel Sep 23, 2024
88e73e7
Began working on payroll cobol demo.
maxvonhippel Jan 9, 2025
ec0281a
more gpt-suggested changes trying to get the cobol to run
maxvonhippel Jan 9, 2025
ff846fe
Getting closer, but currently running into:
maxvonhippel Jan 9, 2025
d162136
Cobol code is now running but it returns malformed output:
vinkabuki Jan 9, 2025
a27aa9c
Removed debug logs from COBOL code.
vinkabuki Jan 9, 2025
3df4c73
Better docstrings.
maxvonhippel Jan 10, 2025
f646a85
improve comments
maxvonhippel Jan 10, 2025
7ac48b4
Fix overflow error.
maxvonhippel Jan 10, 2025
9bcb761
Comment with desired property
maxvonhippel Jan 10, 2025
e131639
Fix cobol installation
maxvonhippel Jan 10, 2025
fbc8a07
Fix error handling and add property
maxvonhippel Jan 10, 2025
20c5fe0
Initiate review of cobol->python translation
maxvonhippel Jan 10, 2025
50c36f1
Fix issue with absolute path
maxvonhippel Jan 10, 2025
14e6982
whitespace
maxvonhippel Jan 10, 2025
14d8549
Clarify WHAT to test
maxvonhippel Jan 10, 2025
d06cec5
fix cobol file path
maxvonhippel Jan 10, 2025
b8bdc68
Indicate which function to test
maxvonhippel Jan 10, 2025
9b616e5
last ditch effort
maxvonhippel Jan 10, 2025
1eeed48
Indicate which function to test
maxvonhippel Jan 10, 2025
12a8908
Improve README
maxvonhippel Jan 10, 2025
aaa15e6
Cobol translation demo (#134)
maxvonhippel Jan 11, 2025
cdb91d4
creating test file
Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,164 @@
.DS_Store
.hypothesis/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
117 changes: 117 additions & 0 deletions AWS/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import boto3
import json
import pulp
from datetime import datetime, timezone
import time

# Initialize AWS clients
cloudwatch = boto3.client('cloudwatch')
kinesis = boto3.client('kinesis')

def put_metric_data(metric_name, value, unit):
"""Put custom metric data to CloudWatch"""

cloudwatch.put_metric_data(
Namespace='CustomMetrics',
MetricData=[
{
'MetricName': metric_name,
'Value': value,
'Unit': unit,
'Timestamp': datetime.now(timezone.utc) # Fixed here
}
]
)

def put_record_to_kinesis(stream_name, data):
"""Put a record to Kinesis Data Stream"""

response = kinesis.put_record(
StreamName=stream_name,
Data=json.dumps(data),
PartitionKey=str(datetime.now(timezone.utc).timestamp())
)
return response

def log_to_cloudwatch(log_group, log_stream, message):
cloudwatch_logs = boto3.client('logs')
cloudwatch_logs.put_log_events(
logGroupName=log_group,
logStreamName=log_stream,
logEvents=[
{
'timestamp': int(time.time() * 1000),
'message': message,
},
]
)

def optimize_production():

"""Optimize production using linear programming and log the results to CloudWatch"""

log_group = 'ProductionOptimizationLogs'
log_stream = 'OptimizationResults'

# Create the LP problem
prob = pulp.LpProblem("Production Optimization", pulp.LpMaximize)

# Define variables
x1 = pulp.LpVariable("Product_1", lowBound=0)
x2 = pulp.LpVariable("Product_2", lowBound=0)

# Define the objective function
prob += 20 * x1 + 30 * x2, "Profit"

# Define constraints
prob += 2 * x1 + 3 * x2 <= 100, "Labor_hours"
prob += 4 * x1 + 3 * x2 <= 120, "Material_units"

# Solve the problem
prob.solve()

# Prepare the results
status = pulp.LpStatus[prob.status]
product1 = x1.varValue
product2 = x2.varValue
total_profit = pulp.value(prob.objective)

# Log the results to CloudWatch
log_to_cloudwatch(log_group, log_stream, f"Status: {status}")
log_to_cloudwatch(log_group, log_stream, "Optimal Production Plan:")
log_to_cloudwatch(log_group, log_stream, f"Product 1: {product1} units")
log_to_cloudwatch(log_group, log_stream, f"Product 2: {product2} units")
log_to_cloudwatch(log_group, log_stream, f"Total Profit: ${total_profit}")

# Send the results to Kinesis
stream_name = 'ProductionOptimizationResults'
data = {
'timestamp': str(datetime.now(timezone.utc)), # Fixed here
'status': status,
'product1': product1,
'product2': product2,
'total_profit': total_profit
}
response = put_record_to_kinesis(stream_name, data)
log_to_cloudwatch(log_group, log_stream, f"Optimization results sent to Kinesis. Shard ID: {response['ShardId']}")

# Return the results
return {
'status': status,
'product1': product1,
'product2': product2,
'total_profit': total_profit
}

if __name__ == "__main__":
# Put a custom metric to CloudWatch
put_metric_data('MyCustomMetric', 42, 'Count')

# Put a record to Kinesis Data Stream
stream_name = 'MyKinesisStream'
data = {
'timestamp': str(datetime.now(timezone.utc)), # Fixed here
'message': 'Hello, Kinesis!'
}
response = put_record_to_kinesis(stream_name, data)
print(f"Record sent to Kinesis. Shard ID: {response['ShardId']}")
2 changes: 2 additions & 0 deletions COBOL/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
payroll
*.txt
76 changes: 76 additions & 0 deletions COBOL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Code Modernization

Astonishingly, 70% of all existing business logic is in COBOL, and 800 billion lines of COBOL are still in use in industry today [1].
Many (perhaps all) companies that still use COBOL wish they could move off it, since it is massively antiquated and the only living engineers who still know it are in retirement homes. Obviously, LLMs present a compelling solution to this problem via automated translation. But how can you be sure the translation is correct? This demo is meant to illustrate how Benchify can fit into the analysis of a translation from COBOL to Python.

You can see the complete report [here](https://github.com/Benchify/benchify-examples/pull/134).

Example usage of the COBOL wrapper:
```
ipython3
Python 3.9.6 (default, Nov 11 2024, 03:15:38)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from script import *
...: install_cobc_and_compile_script()
...:
...: employee_records = [
...: EmployeeRecord(emp_id="12345", hours_worked=40, hourly_rate=20.0, tax_deduction=50.0),
...: EmployeeRecord(emp_id="67890", hours_worked=35, hourly_rate=15.0, tax_deduction=30.0),
...: EmployeeRecord(emp_id="54321", hours_worked=45, hourly_rate=25.0, tax_deduction=70.0)
...: ]
...:
...: payroll_results = process_payroll_cobol(employee_records)
...: payroll_results
GNU COBOL (cobc) is already installed.
Compiling payroll.cbl...
Compilation successful.
GNU COBOL (cobc) is already installed.
Compiling payroll.cbl...
Compilation successful.
=== Debug: Writing the following lines to input file ===
1234504000020000005000
6789003500015000003000
5432104500025000007000
=======================================================
Running the COBOL payroll program with file: temp_payroll_input_ceacb40a807b19a0.txt
Processing COBOL output...
=== Raw COBOL Output ===
EMP-ID,GROSS-PAY,NET-PAY
12345,0000800.00,0000750.00
67890,0000525.00,0000495.00
54321,0001125.00,0001055.00
=========================
Employee ID: 12345
Gross Pay: $800.00
Net Pay: $750.00
Employee ID: 67890
Gross Pay: $525.00
Net Pay: $495.00
Employee ID: 54321
Gross Pay: $1125.00
Net Pay: $1055.00
Out[1]: [(800.0, 750.0), (525.0, 495.0), (1125.0, 1055.0)]

In [2]: payroll_results_2 = process_payroll(employee_records)
Employee ID: 12345
Gross Pay: $800.00
Net Pay: $750.00
Employee ID: 67890
Gross Pay: $525.00
Net Pay: $495.00
Employee ID: 54321
Gross Pay: $1125.00
Net Pay: $1055.00

In [3]: payroll_results_2
Out[3]: [(800.0, 750.0), (525.0, 495.0), (1125.0, 1055.0)]

In [4]: payroll_results_2 == payroll_results
Out[4]: True

In [5]: exit()
```

[1]: https://cobolcowboys.com/cobol-today/#:~:text=70%25%20of%20all%20critical%20business,use%20today%20by%20various%20industries.
Loading