From 68c43c6c0cb920ca9bfc5b5c9ddc50888f2ed13e Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:30:14 +0000 Subject: [PATCH 01/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in ad6a95a according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/tests/integration_tests/test_ui.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tests/integration_tests/test_ui.py b/src/tests/integration_tests/test_ui.py index 9d7546cde..60627e4e2 100644 --- a/src/tests/integration_tests/test_ui.py +++ b/src/tests/integration_tests/test_ui.py @@ -2,13 +2,15 @@ import pytest from selenium import webdriver from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.ui import WebDriverWait + @pytest.fixture def browser(): return webdriver.Chrome() + def test_login(browser): # Test login functionality browser.get("https://pi-nexus-autonomous-banking-network.com/login") @@ -19,12 +21,14 @@ def test_login(browser): browser.find_element_by_name("login").click() WebDriverWait(browser, 10).until(EC.title_contains("Dashboard")) + def test_account_list(browser): # Test account list page browser.get("https://pi-nexus-autonomous-banking-network.com/accounts") account_list = browser.find_elements_by_css_selector(".account-list li") assert len(account_list) > 0 + def test_create_account(browser): # Test create account functionality browser.get("https://pi-nexus-autonomous-banking-network.com/accounts/new") From 89bf6983acf1db2f513c6753fa3ff42d82b314a0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:33:58 +0000 Subject: [PATCH 02/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in fda8ed8 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/routes/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/index.js b/src/routes/index.js index d1800ab91..cdb9ac6b2 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,8 +1,8 @@ -const express = require("express"); -const router = express.Router(); +const express = require('express') +const router = express.Router() -router.get("/", (req, res) => { - res.json({ message: "Welcome to the PI Nexus Autonomous Banking Network!" }); -}); +router.get('/', (req, res) => { + res.json({ message: 'Welcome to the PI Nexus Autonomous Banking Network!' }) +}) -module.exports = router; +module.exports = router From e7253c1dac864a34497f94cde16bf76eccd5dcac Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:34:57 +0000 Subject: [PATCH 03/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 89e8652 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/models/user.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/models/user.js b/src/models/user.js index e827eec76..2e171d0da 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -1,20 +1,20 @@ -const mongoose = require("mongoose"); -const bcrypt = require("bcrypt"); +const mongoose = require('mongoose') +const bcrypt = require('bcrypt') const UserSchema = new mongoose.Schema({ username: { type: String, required: true, unique: true }, - password: { type: String, required: true }, -}); + password: { type: String, required: true } +}) -UserSchema.pre("save", async function (next) { - if (this.isModified("password")) { - this.password = await bcrypt.hash(this.password, 10); +UserSchema.pre('save', async function (next) { + if (this.isModified('password')) { + this.password = await bcrypt.hash(this.password, 10) } - next(); -}); + next() +}) UserSchema.methods.comparePassword = function (password) { - return bcrypt.compare(password, this.password); -}; + return bcrypt.compare(password, this.password) +} -module.exports = mongoose.model("User", UserSchema); +module.exports = mongoose.model('User', UserSchema) From ffd3862b912eb5a9c04ee9c890001b094a11413e Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:35:43 +0000 Subject: [PATCH 04/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 89490a3 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/controllers/accounts.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 7a59dbdaf..8b93c643f 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -1,16 +1,16 @@ -const Account = require("../models/account"); +const Account = require('../models/account') exports.list = async (req, res) => { - const accounts = await Account.find({ owner: req.user._id }); - res.json(accounts); -}; + const accounts = await Account.find({ owner: req.user._id }) + res.json(accounts) +} exports.create = async (req, res) => { const account = new Account({ account_name: req.body.account_name, initial_balance: req.body.initial_balance, - owner: req.user._id, - }); - await account.save(); - res.json({ message: "Account created!", account }); -}; + owner: req.user._id + }) + await account.save() + res.json({ message: 'Account created!', account }) +} From 42bfd84fe4d375635f12d40ba1cff54c8dd527a0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:36:46 +0000 Subject: [PATCH 05/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2c80799 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/controllers/transfers.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/controllers/transfers.js b/src/controllers/transfers.js index ecc8b9e1f..b20c4b778 100644 --- a/src/controllers/transfers.js +++ b/src/controllers/transfers.js @@ -1,31 +1,31 @@ -const Transfer = require("../models/transfer"); -const Account = require("../models/account"); +const Transfer = require('../models/transfer') +const Account = require('../models/account') exports.create = async (req, res) => { - const senderAccount = await Account.findById(req.body.sender_account_id); - const receiverAccount = await Account.findById(req.body.receiver_account_id); + const senderAccount = await Account.findById(req.body.sender_account_id) + const receiverAccount = await Account.findById(req.body.receiver_account_id) if (!senderAccount || !receiverAccount) { - return res.status(400).json({ message: "Account not found" }); + return res.status(400).json({ message: 'Account not found' }) } if (senderAccount.balance < req.body.amount) { - return res.status(400).json({ message: "Insufficient balance" }); + return res.status(400).json({ message: 'Insufficient balance' }) } const transfer = new Transfer({ sender_account_id: req.body.sender_account_id, receiver_account_id: req.body.receiver_account_id, - amount: req.body.amount, - }); + amount: req.body.amount + }) - await transfer.save(); + await transfer.save() - senderAccount.balance -= req.body.amount; - receiverAccount.balance += req.body.amount; + senderAccount.balance -= req.body.amount + receiverAccount.balance += req.body.amount - await senderAccount.save(); - await receiverAccount.save(); + await senderAccount.save() + await receiverAccount.save() - res.json({ message: "Transfer successful", transfer }); -}; + res.json({ message: 'Transfer successful', transfer }) +} From 80b0ed96b169f472a8d8a9f9d45e6920e92c47d5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:39:06 +0000 Subject: [PATCH 06/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 0f8e78e according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/controllers/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/index.js b/src/controllers/index.js index 639a0fa07..6a19656de 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -1,10 +1,10 @@ -const express = require("express"); -const router = express.Router(); +const express = require('express') +const router = express.Router() -const AccountsController = require("./accounts"); -const TransfersController = require("./transfers"); +const AccountsController = require('./accounts') +const TransfersController = require('./transfers') -router.use("/accounts", AccountsController); -router.use("/transfers", TransfersController); +router.use('/accounts', AccountsController) +router.use('/transfers', TransfersController) -module.exports = router; +module.exports = router From a24ae6c88fad1cff68e196c712087dc036b429e8 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:40:03 +0000 Subject: [PATCH 07/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 6689b93 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/middleware/auth.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/middleware/auth.js b/src/middleware/auth.js index 46ae82670..3c436ec5a 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1,20 +1,20 @@ -const jwt = require("jsonwebtoken"); -const User = require("../models/user"); +const jwt = require('jsonwebtoken') +const User = require('../models/user') const authenticate = async (req, res, next) => { - const token = req.header("Authorization")?.split(" ")[1]; + const token = req.header('Authorization')?.split(' ')[1] if (!token) { - return res.status(401).json({ message: "Access Denied" }); + return res.status(401).json({ message: 'Access Denied' }) } try { - const decoded = jwt.verify(token, process.env.JWT_SECRET); - req.user = await User.findById(decoded.user_id); - next(); + const decoded = jwt.verify(token, process.env.JWT_SECRET) + req.user = await User.findById(decoded.user_id) + next() } catch (error) { - res.status(400).json({ message: "Invalid Token" }); + res.status(400).json({ message: 'Invalid Token' }) } -}; +} -module.exports = authenticate; +module.exports = authenticate From d5de6876c59ca1eb7b58b298745fd94392450c71 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:41:06 +0000 Subject: [PATCH 08/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in eb12002 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/middleware/network.js | 42 ++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/middleware/network.js b/src/middleware/network.js index 8e58f6c1b..636f053e5 100644 --- a/src/middleware/network.js +++ b/src/middleware/network.js @@ -1,30 +1,40 @@ -const { PRIVATE_KEY, PRIVATE_KEY_PASSWORD, PRIVATE_KEY_PASSWORD_SALT, ENDPOINT, CHAIN_ID } = process.env; +const { + PRIVATE_KEY, + PRIVATE_KEY_PASSWORD, + PRIVATE_KEY_PASSWORD_SALT, + ENDPOINT, + CHAIN_ID +} = process.env -const Web3 = require("web3"); -const EthereumTx = require("ethereumjs-tx"); +const Web3 = require('web3') +const EthereumTx = require('ethereumjs-tx') -const web3 = new Web3(new Web3.providers.HttpProvider(ENDPOINT)); +const web3 = new Web3(new Web3.providers.HttpProvider(ENDPOINT)) const createTransaction = async (from, to, value) => { - const nonce = await web3.eth.getTransactionCount(from); - const gasPrice = await web3.eth.getGasPrice(); - const gasLimit = 21000; + const nonce = await web3.eth.getTransactionCount(from) + const gasPrice = await web3.eth.getGasPrice() + const gasLimit = 21000 const tx = new EthereumTx({ nonce, gasPrice, gasLimit, to, - value, - }); + value + }) - const privateKey = web3.utils.sha3(PRIVATE_KEY_PASSWORD + PRIVATE_KEY_PASSWORD_SALT); - tx.sign(privateKey); + const privateKey = web3.utils.sha3( + PRIVATE_KEY_PASSWORD + PRIVATE_KEY_PASSWORD_SALT + ) + tx.sign(privateKey) - const serializedTx = tx.serialize(); - const transactionHash = await web3.eth.sendSignedTransaction("0x" + serializedTx.toString("hex")); + const serializedTx = tx.serialize() + const transactionHash = await web3.eth.sendSignedTransaction( + '0x' + serializedTx.toString('hex') + ) - return transactionHash; -}; + return transactionHash +} -module.exports = createTransaction; +module.exports = createTransaction From 55734341a1313c63084a5eadf1b78eff52c6ccfc Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:42:03 +0000 Subject: [PATCH 09/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 564f06c according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/routes/transfers.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/routes/transfers.js b/src/routes/transfers.js index 01b221fe7..a61bd45bc 100644 --- a/src/routes/transfers.js +++ b/src/routes/transfers.js @@ -1,20 +1,24 @@ -const express = require("express"); -const router = express.Router(); +const express = require('express') +const router = express.Router() -const TransferController = require("../controllers/transfers"); -const authenticate = require("../middleware/auth"); -const createTransaction = require("../middleware/network"); +const TransferController = require('../controllers/transfers') +const authenticate = require('../middleware/auth') +const createTransaction = require('../middleware/network') -router.post("/", authenticate, async (req, res) => { +router.post('/', authenticate, async (req, res) => { try { - const transfer = await TransferController.create(req, res); - const transactionHash = await createTransaction(req.user.wallet_address, req.body.receiver_account_id, req.body.amount); - transfer.transaction_hash = transactionHash; - await transfer.save(); - res.json({ message: "Transfer successful", transfer }); + const transfer = await TransferController.create(req, res) + const transactionHash = await createTransaction( + req.user.wallet_address, + req.body.receiver_account_id, + req.body.amount + ) + transfer.transaction_hash = transactionHash + await transfer.save() + res.json({ message: 'Transfer successful', transfer }) } catch (error) { - res.status(400).json({ message: error.message }); + res.status(400).json({ message: error.message }) } -}); +}) -module.exports = router; +module.exports = router From b5bdfa51bc9c94e5a9e9153437e8be7ffc6f2fb7 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:45:17 +0000 Subject: [PATCH 10/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in b6c1ce5 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/app.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/app.js b/src/app.js index a2ed7cd55..286ba6401 100644 --- a/src/app.js +++ b/src/app.js @@ -1,35 +1,35 @@ -const express = require("express"); -const bodyParser = require("body-parser"); -const cors = require("cors"); -const mongoose = require("mongoose"); +const express = require('express') +const bodyParser = require('body-parser') +const cors = require('cors') +const mongoose = require('mongoose') -const { JWT_SECRET, MONGODB_URI } = process.env; +const { JWT_SECRET, MONGODB_URI } = process.env -const app = express(); +const app = express() -app.use(bodyParser.json()); -app.use(cors()); +app.use(bodyParser.json()) +app.use(cors()) -const router = require("./routes"); -app.use("/api", router); +const router = require('./routes') +app.use('/api', router) const connectToMongoDB = async () => { try { await mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true, - useCreateIndex: true, - }); - console.log("Connected to MongoDB"); + useCreateIndex: true + }) + console.log('Connected to MongoDB') } catch (error) { - console.error("Failed to connect to MongoDB", error); - process.exit(1); + console.error('Failed to connect to MongoDB', error) + process.exit(1) } -}; +} -connectToMongoDB(); +connectToMongoDB() -const PORT = process.env.PORT || 5000; +const PORT = process.env.PORT || 5000 app.listen(PORT, () => { - console.log(`Server running on port ${PORT}`); -}); + console.log(`Server running on port ${PORT}`) +}) From da49bfabc41058a06e53632a57af115bbab540d1 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 07:47:47 +0000 Subject: [PATCH 11/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 6ec06f1 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- src/models/transfer.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/models/transfer.js b/src/models/transfer.js index d1cf4802b..ca77421f7 100644 --- a/src/models/transfer.js +++ b/src/models/transfer.js @@ -1,12 +1,16 @@ -const mongoose = require("mongoose"); +const mongoose = require('mongoose') const transferSchema = new mongoose.Schema({ - sender_id: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true }, + sender_id: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User', + required: true + }, receiver_account_id: { type: String, required: true }, amount: { type: Number, required: true }, - transaction_hash: { type: String }, -}); + transaction_hash: { type: String } +}) -const Transfer = mongoose.model("Transfer", transferSchema); +const Transfer = mongoose.model('Transfer', transferSchema) -module.exports = Transfer; +module.exports = Transfer From 485044ae1ccf7f086420ab8ae29aaf7660247cee Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:27:48 +0000 Subject: [PATCH 12/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 6c0eb5a according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- risk_management/risk_assessment.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/risk_management/risk_assessment.py b/risk_management/risk_assessment.py index 6bdb51647..22e91a390 100644 --- a/risk_management/risk_assessment.py +++ b/risk_management/risk_assessment.py @@ -3,14 +3,17 @@ from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split + class RiskAssessment: def __init__(self, data): self.data = data - self.X = self.data.drop('risk_level', axis=1) - self.y = self.data['risk_level'] + self.X = self.data.drop("risk_level", axis=1) + self.y = self.data["risk_level"] def train_model(self): - X_train, X_test, y_train, y_test = train_test_split(self.X, self.y, test_size=0.2, random_state=42) + X_train, X_test, y_train, y_test = train_test_split( + self.X, self.y, test_size=0.2, random_state=42 + ) self.model = RandomForestClassifier(n_estimators=100, random_state=42) self.model.fit(X_train, y_train) From 79927ba69a05f3fb87b26ebc12bf45ab59d2319b Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:28:26 +0000 Subject: [PATCH 13/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 22c05ff according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- risk_management/risk_mitigation.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/risk_management/risk_mitigation.py b/risk_management/risk_mitigation.py index 77d3327ca..c7166831e 100644 --- a/risk_management/risk_mitigation.py +++ b/risk_management/risk_mitigation.py @@ -4,13 +4,13 @@ def __init__(self, risk_assessment_model): def mitigate_risk(self, transaction): risk_level = self.risk_assessment_model.predict_risk(transaction) - if risk_level == 'high': + if risk_level == "high": # Implement risk mitigation strategies here # For example, you could flag the transaction for review or decline it altogether - return 'Flagged for review' - elif risk_level == 'medium': + return "Flagged for review" + elif risk_level == "medium": # Implement risk mitigation strategies here # For example, you could require additional authentication or verification - return 'Additional authentication required' + return "Additional authentication required" else: - return 'Transaction approved' + return "Transaction approved" From 6b60c228b4877663e3358a9f10694061ba7d9c93 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:29:00 +0000 Subject: [PATCH 14/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in a50f1a4 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- risk_management/risk_monitoring.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/risk_management/risk_monitoring.py b/risk_management/risk_monitoring.py index 52eaa2db9..653c69773 100644 --- a/risk_management/risk_monitoring.py +++ b/risk_management/risk_monitoring.py @@ -1,5 +1,6 @@ import time + class RiskMonitoring: def __init__(self, risk_assessment_model, risk_mitigation_model): self.risk_assessment_model = risk_assessment_model @@ -8,12 +9,16 @@ def __init__(self, risk_assessment_model, risk_mitigation_model): def monitor_risks(self, transactions): for transaction in transactions: risk_level = self.risk_assessment_model.predict_risk(transaction) - if risk_level == 'high': - mitigation_result = self.risk_mitigation_model.mitigate_risk(transaction) - print(f'High-risk transaction detected: {mitigation_result}') - elif risk_level == 'medium': - mitigation_result = self.risk_mitigation_model.mitigate_risk(transaction) - print(f'Medium-risk transaction detected: {mitigation_result}') + if risk_level == "high": + mitigation_result = self.risk_mitigation_model.mitigate_risk( + transaction + ) + print(f"High-risk transaction detected: {mitigation_result}") + elif risk_level == "medium": + mitigation_result = self.risk_mitigation_model.mitigate_risk( + transaction + ) + print(f"Medium-risk transaction detected: {mitigation_result}") else: - print(f'Low-risk transaction detected: Transaction approved') + print(f"Low-risk transaction detected: Transaction approved") time.sleep(1) From 2f9145a4eb9da80e3ea26a6ffa4e605c7c375a4f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:30:55 +0000 Subject: [PATCH 15/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 5e79cd2 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- fraud_detection/fraud_detection_model.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fraud_detection/fraud_detection_model.py b/fraud_detection/fraud_detection_model.py index 7182d5030..edac1a2fa 100644 --- a/fraud_detection/fraud_detection_model.py +++ b/fraud_detection/fraud_detection_model.py @@ -3,14 +3,17 @@ from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split + class FraudDetectionModel: def __init__(self, data): self.data = data - self.X = self.data.drop('fraudulent', axis=1) - self.y = self.data['fraudulent'] + self.X = self.data.drop("fraudulent", axis=1) + self.y = self.data["fraudulent"] def train_model(self): - X_train, X_test, y_train, y_test = train_test_split(self.X, self.y, test_size=0.2, random_state=42) + X_train, X_test, y_train, y_test = train_test_split( + self.X, self.y, test_size=0.2, random_state=42 + ) self.model = RandomForestClassifier(n_estimators=100, random_state=42) self.model.fit(X_train, y_train) From c33a43b380a578fa86cd2a7ecc932d25990ec5e2 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:31:32 +0000 Subject: [PATCH 16/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 0f53969 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- fraud_detection/anomaly_detection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fraud_detection/anomaly_detection.py b/fraud_detection/anomaly_detection.py index 290777c23..1295cd588 100644 --- a/fraud_detection/anomaly_detection.py +++ b/fraud_detection/anomaly_detection.py @@ -2,6 +2,7 @@ import pandas as pd from sklearn.ensemble import IsolationForest + class AnomalyDetection: def __init__(self, transaction_data): self.transaction_data = transaction_data From e7c52aa573167b9b7b4bfd3aa2b02747a22b0578 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:32:12 +0000 Subject: [PATCH 17/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 9e452d3 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- fraud_detection/fraud_response.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fraud_detection/fraud_response.py b/fraud_detection/fraud_response.py index b4ee601cd..199695e3e 100644 --- a/fraud_detection/fraud_response.py +++ b/fraud_detection/fraud_response.py @@ -6,13 +6,13 @@ def __init__(self, fraud_detection_model, anomaly_detection): def respond_to_fraud(self, transactions): for transaction in transactions: fraud_level = self.fraud_detection_model.predict_fraud(transaction) - if fraud_level == 'fraudulent': + if fraud_level == "fraudulent": anomaly_score = self.anomaly_detection.detect_anomalies(transaction) if anomaly_score == -1: # Implement fraud response strategies here # For example, you could flag the transaction for review or decline it altogether - print('Fraudulent transaction detected: Flagged for review') + print("Fraudulent transaction detected: Flagged for review") else: - print('Anomalous transaction detected: Flagged for review') + print("Anomalous transaction detected: Flagged for review") else: - print('Non-fraudulent transaction detected: Transaction approved') + print("Non-fraudulent transaction detected: Transaction approved") From b7e68ab2de5af5e1c68508a1e68df88b2afd403c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:34:37 +0000 Subject: [PATCH 18/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 76f80ff according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- customer_service/knowledge_base.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/customer_service/knowledge_base.py b/customer_service/knowledge_base.py index eab799fb7..267a37c3a 100644 --- a/customer_service/knowledge_base.py +++ b/customer_service/knowledge_base.py @@ -1,18 +1,18 @@ class KnowledgeBase: def __init__(self): self.knowledge_base = { - 'account': { - 'open': 'To open a new account, please visit our website and fill out the account opening form.', - 'close': 'To close an existing account, please contact our customer support team.', - 'balance': 'To check your account balance, please log in to your account on our website or mobile app.' + "account": { + "open": "To open a new account, please visit our website and fill out the account opening form.", + "close": "To close an existing account, please contact our customer support team.", + "balance": "To check your account balance, please log in to your account on our website or mobile app.", }, - 'transaction': { - 'make': 'To make a new transaction, please log in to your account on our website or mobile app.', - 'history': 'To view your transaction history, please log in to your account on our website or mobile app.' + "transaction": { + "make": "To make a new transaction, please log in to your account on our website or mobile app.", + "history": "To view your transaction history, please log in to your account on our website or mobile app.", + }, + "other": { + "help": "For assistance, please contact our customer support team." }, - 'other': { - 'help': 'For assistance, please contact our customer support team.' - } } def get_response(self, intent): @@ -21,4 +21,4 @@ def get_response(self, intent): if value: return self.knowledge_base[key] else: - return self.knowledge_base['other'] + return self.knowledge_base["other"] From 8bad75308164cbed814c02d5b825da00c0dcfe6d Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:35:08 +0000 Subject: [PATCH 19/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2e40b65 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- customer_service/natural_language_processing.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/customer_service/natural_language_processing.py b/customer_service/natural_language_processing.py index 07490f49a..6a1aef356 100644 --- a/customer_service/natural_language_processing.py +++ b/customer_service/natural_language_processing.py @@ -1,6 +1,7 @@ import spacy -nlp = spacy.load('en_core_web_sm') +nlp = spacy.load("en_core_web_sm") + class NLP: def __init__(self): @@ -13,14 +14,14 @@ def extract_entities(self, text): def extract_intent(self, text): doc = self.nlp(text) - intents = {'account': False, 'transaction': False, 'other': False} + intents = {"account": False, "transaction": False, "other": False} for token in doc: - if token.text.lower() in ['account', 'accounts']: - intents['account'] = True - elif token.text.lower() in ['transaction', 'transactions']: - intents['transaction'] = True + if token.text.lower() in ["account", "accounts"]: + intents["account"] = True + elif token.text.lower() in ["transaction", "transactions"]: + intents["transaction"] = True if any(intents.values()): return intents else: - intents['other'] = True + intents["other"] = True return intents From 02498383dd22ece0ab4d8f1d9345504a4534891c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:35:18 +0000 Subject: [PATCH 20/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 896f93f according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- customer_service/chatbot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/customer_service/chatbot.py b/customer_service/chatbot.py index 8ff98a9a1..786d199bd 100644 --- a/customer_service/chatbot.py +++ b/customer_service/chatbot.py @@ -1,5 +1,6 @@ import time + class Chatbot: def __init__(self, nlp_model, knowledge_base): self.nlp_model = nlp_model @@ -9,6 +10,6 @@ def chat(self, user_input): entities = self.nlp_model.extract_entities(user_input) intent = self.nlp_model.extract_intent(user_input) response = self.knowledge_base.get_response(intent) - print('User:', user_input) - print('Chatbot:', response) + print("User:", user_input) + print("Chatbot:", response) time.sleep(1) From 5e6d39e0812b60e65ceaa38144822b2ba85dd6a8 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:37:12 +0000 Subject: [PATCH 21/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 978d3bc according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- .../transaction_validation.py | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/transaction_processing/transaction_validation.py b/transaction_processing/transaction_validation.py index f119832ff..23da6ba7e 100644 --- a/transaction_processing/transaction_validation.py +++ b/transaction_processing/transaction_validation.py @@ -1,17 +1,18 @@ import re + class TransactionValidation: def __init__(self): self.validation_rules = { - 'account_number': { - 'regex': r'^\d{10}$', - 'message': 'Invalid account number format. Please enter a 10-digit account number.' + "account_number": { + "regex": r"^\d{10}$", + "message": "Invalid account number format. Please enter a 10-digit account number.", + }, + "amount": { + "min": 0, + "max": 1000000, + "message": "Transaction amount must be between 0 and 1,000,000.", }, - 'amount': { - 'min': 0, - 'max': 1000000, - 'message': 'Transaction amount must be between 0 and 1,000,000.' - } } def validate_transaction(self, transaction): @@ -19,13 +20,17 @@ def validate_transaction(self, transaction): for field, rules in self.validation_rules.items(): if field in transaction: for rule in rules: - if rule == 'regex': + if rule == "regex": if not re.match(rules[rule], transaction[field]): - errors.append(rules['message']) - elif rule == 'min': + errors.append(rules["message"]) + elif rule == "min": if float(transaction[field]) < rules[rule]: - errors.append(f'Transaction amount must be at least {rules[rule]}') - elif rule == 'max': + errors.append( + f"Transaction amount must be at least {rules[rule]}" + ) + elif rule == "max": if float(transaction[field]) > rules[rule]: - errors.append(f'Transaction amount must not exceed {rules[rule]}') + errors.append( + f"Transaction amount must not exceed {rules[rule]}" + ) return errors From 8660b46cdb209f4f63422bd9841bcc2a2799b342 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:37:51 +0000 Subject: [PATCH 22/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in fd4163d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- transaction_processing/transaction_routing.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/transaction_processing/transaction_routing.py b/transaction_processing/transaction_routing.py index e11ee5ea2..499748e38 100644 --- a/transaction_processing/transaction_routing.py +++ b/transaction_processing/transaction_routing.py @@ -1,18 +1,20 @@ class TransactionRouter: def __init__(self): self.routing_rules = { - 'domestic': { - 'regex': r'^\d{10}$', - 'message': 'Invalid account number format. Please enter a 10-digit account number.' + "domestic": { + "regex": r"^\d{10}$", + "message": "Invalid account number format. Please enter a 10-digit account number.", + }, + "international": { + "regex": r"^\d{12}$", + "message": "Invalid account number format. Please enter a 12-digit account number.", }, - 'international': { - 'regex': r'^\d{12}$', - 'message': 'Invalid account number format. Please enter a 12-digit account number.' - } } def route_transaction(self, transaction): for rule in self.routing_rules: - if re.match(self.routing_rules[rule]['regex'], transaction['account_number']): + if re.match( + self.routing_rules[rule]["regex"], transaction["account_number"] + ): return rule - raise ValueError('Invalid account number format.') + raise ValueError("Invalid account number format.") From 057a7d44c835d28b79132f29c66146cbd26a5fa0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:38:25 +0000 Subject: [PATCH 23/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in d504395 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- transaction_processing/transaction_processing.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/transaction_processing/transaction_processing.py b/transaction_processing/transaction_processing.py index df41a2cb5..133311667 100644 --- a/transaction_processing/transaction_processing.py +++ b/transaction_processing/transaction_processing.py @@ -1,5 +1,6 @@ import time + class TransactionProcessor: def __init__(self, transaction_validator, transaction_router): self.transaction_validator = transaction_validator @@ -8,11 +9,11 @@ def __init__(self, transaction_validator, transaction_router): def process_transaction(self, transaction): errors = self.transaction_validator.validate_transaction(transaction) if errors: - print('Transaction errors:', errors) + print("Transaction errors:", errors) return False else: channel = self.transaction_router.route_transaction(transaction) - print('Transaction routed to:', channel) + print("Transaction routed to:", channel) time.sleep(1) - print('Transaction processed successfully.') + print("Transaction processed successfully.") return True From 6115a10ed0183c4389ddc77018b6ad8e01e98b4f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:41:30 +0000 Subject: [PATCH 24/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 607fe54 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- data_analytics/data_ingestion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/data_analytics/data_ingestion.py b/data_analytics/data_ingestion.py index 7cf151c16..5183e94cc 100644 --- a/data_analytics/data_ingestion.py +++ b/data_analytics/data_ingestion.py @@ -1,5 +1,6 @@ import pandas as pd + class DataIngestion: def __init__(self, data_source): self.data_source = data_source From 33febf4d5ae9cc85b290be6f7bcf959e009a6c9f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:41:55 +0000 Subject: [PATCH 25/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 6972938 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- data_analytics/data_analysis.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/data_analytics/data_analysis.py b/data_analytics/data_analysis.py index 20bc30414..88523a5c6 100644 --- a/data_analytics/data_analysis.py +++ b/data_analytics/data_analysis.py @@ -2,6 +2,7 @@ import pandas as pd from sklearn.cluster import KMeans + class DataAnalysis: def __init__(self, data): self.data = data @@ -9,16 +10,18 @@ def __init__(self, data): def analyze_data(self): # Perform data cleaning and preprocessing self.data = self.data.dropna() - self.data = pd.get_dummies(self.data, columns=['transaction_type']) + self.data = pd.get_dummies(self.data, columns=["transaction_type"]) # Perform data analysis - kmeans = KMeans(n_clusters=3, random_state=0).fit(self.data[['amount', 'frequency']]) - self.data['cluster'] = kmeans.labels_ + kmeans = KMeans(n_clusters=3, random_state=0).fit( + self.data[["amount", "frequency"]] + ) + self.data["cluster"] = kmeans.labels_ # Perform statistical analysis summary_stats = self.data.describe() - summary_stats.loc['count'] = len(self.data) - summary_stats.loc['mean'] = np.mean(self.data) - summary_stats.loc['std'] = np.std(self.data) + summary_stats.loc["count"] = len(self.data) + summary_stats.loc["mean"] = np.mean(self.data) + summary_stats.loc["std"] = np.std(self.data) return summary_stats From b7008e947202f7868b732d111fb13d9d4cecfa33 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:42:10 +0000 Subject: [PATCH 26/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 7fb3d57 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- data_analytics/data_visualization.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data_analytics/data_visualization.py b/data_analytics/data_visualization.py index 96414dd96..3f711a046 100644 --- a/data_analytics/data_visualization.py +++ b/data_analytics/data_visualization.py @@ -1,16 +1,17 @@ import plotly.express as px + class DataVisualization: def __init__(self, data): self.data = data def visualize_data(self): # Create interactive dashboards - fig = px.scatter(self.data, x='amount', y='frequency', color='cluster') + fig = px.scatter(self.data, x="amount", y="frequency", color="cluster") fig.show() - fig = px.histogram(self.data, x='transaction_type', nbins=20) + fig = px.histogram(self.data, x="transaction_type", nbins=20) fig.show() - fig = px.box(self.data, x='cluster', y='amount') + fig = px.box(self.data, x="cluster", y="amount") fig.show() From 6da95e80204b689df0fa74169c55bd283bcba8eb Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:43:31 +0000 Subject: [PATCH 27/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 1c54c9a according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- security/authentication.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/security/authentication.py b/security/authentication.py index f85c9eb66..54d08b6c3 100644 --- a/security/authentication.py +++ b/security/authentication.py @@ -1,14 +1,19 @@ import hashlib import secrets + class Authentication: def __init__(self): self.salt = secrets.token_hex(16) def generate_password_hash(self, password): - password_hash = hashlib.pbkdf2_hmac('sha256', password.encode(), self.salt.encode(), 100000) + password_hash = hashlib.pbkdf2_hmac( + "sha256", password.encode(), self.salt.encode(), 100000 + ) return password_hash.hex() def verify_password(self, password, password_hash): - password_hash_check = hashlib.pbkdf2_hmac('sha256', password.encode(), self.salt.encode(), 100000) + password_hash_check = hashlib.pbkdf2_hmac( + "sha256", password.encode(), self.salt.encode(), 100000 + ) return password_hash_check.hex() == password_hash From 92ceca2a091895a1dff8f25edb7473f23bf22fcc Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:46:36 +0000 Subject: [PATCH 28/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 8c0dbcc according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- system_monitoring/system_monitoring.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/system_monitoring/system_monitoring.py b/system_monitoring/system_monitoring.py index 9db46a92e..2c874966e 100644 --- a/system_monitoring/system_monitoring.py +++ b/system_monitoring/system_monitoring.py @@ -1,18 +1,20 @@ -import psutil import time +import psutil + + class SystemMonitoring: def __init__(self): self.cpu_percent = psutil.cpu_percent() self.memory_percent = psutil.virtual_memory().percent - self.disk_percent = psutil.disk_usage('/').percent + self.disk_percent = psutil.disk_usage("/").percent def monitor_system(self): while True: time.sleep(60) self.cpu_percent = psutil.cpu_percent() self.memory_percent = psutil.virtual_memory().percent - self.disk_percent = psutil.disk_usage('/').percent - print(f'CPU: {self.cpu_percent}%') - print(f'Memory: {self.memory_percent}%') - print(f'Disk: {self.disk_percent}%') + self.disk_percent = psutil.disk_usage("/").percent + print(f"CPU: {self.cpu_percent}%") + print(f"Memory: {self.memory_percent}%") + print(f"Disk: {self.disk_percent}%") From 142eef2fd3590b2473140e012dbd798bb2c0e470 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:47:06 +0000 Subject: [PATCH 29/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in a442f07 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- system_monitoring/issue_detection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system_monitoring/issue_detection.py b/system_monitoring/issue_detection.py index 8e65205c6..ee70d6e36 100644 --- a/system_monitoring/issue_detection.py +++ b/system_monitoring/issue_detection.py @@ -4,8 +4,8 @@ def __init__(self, system_monitoring): def detect_issues(self): if self.system_monitoring.cpu_percent > 80: - print('High CPU usage detected!') + print("High CPU usage detected!") if self.system_monitoring.memory_percent > 80: - print('High memory usage detected!') + print("High memory usage detected!") if self.system_monitoring.disk_percent > 80: - print('High disk usage detected!') + print("High disk usage detected!") From 4c5947a79d200871e99b7e91cbaed4e0034600c6 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:48:03 +0000 Subject: [PATCH 30/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 01d2c0f according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- system_monitoring/self_healing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system_monitoring/self_healing.py b/system_monitoring/self_healing.py index c0cc472de..f88eed8f4 100644 --- a/system_monitoring/self_healing.py +++ b/system_monitoring/self_healing.py @@ -1,10 +1,11 @@ import subprocess + class SelfHealing: def __init__(self): pass def heal_system(self): # Implement automatic healing techniques - subprocess.run(['systemctl', 'restart', 'nginx']) - subprocess.run(['systemctl', 'restart', 'postgresql']) + subprocess.run(["systemctl", "restart", "nginx"]) + subprocess.run(["systemctl", "restart", "postgresql"]) From 9964671466c3ce456a9901fa2fc96dfde85f94f9 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:55:25 +0000 Subject: [PATCH 31/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in d94390d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- network/networking.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/network/networking.py b/network/networking.py index 0425688bf..177b46779 100644 --- a/network/networking.py +++ b/network/networking.py @@ -1,8 +1,9 @@ import socket + class Networking: def __init__(self): - self.host = '0.0.0.0' + self.host = "0.0.0.0" self.port = 8080 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.bind((self.host, self.port)) @@ -11,7 +12,7 @@ def listen_for_connections(self): self.socket.listen(5) while True: connection, address = self.socket.accept() - print(f'Connection from {address} has been established!') + print(f"Connection from {address} has been established!") self.handle_connection(connection) def handle_connection(self, connection): From 1f0eaf436f5c55b8659efe5b3f53cc81b703398d Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:56:43 +0000 Subject: [PATCH 32/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2f1562d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- database/database.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/database/database.py b/database/database.py index e8b01f30d..297d7e2e7 100644 --- a/database/database.py +++ b/database/database.py @@ -1,20 +1,27 @@ import sqlite3 + class Database: def __init__(self): - self.connection = sqlite3.connect('banking.db') + self.connection = sqlite3.connect("banking.db") self.cursor = self.connection.cursor() def create_table(self): - self.cursor.execute('''CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, name TEXT, balance REAL)''') + self.cursor.execute( + """CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, name TEXT, balance REAL)""" + ) self.connection.commit() def insert_account(self, name, balance): - self.cursor.execute("INSERT INTO accounts (name, balance) VALUES (?, ?)", (name, balance)) + self.cursor.execute( + "INSERT INTO accounts (name, balance) VALUES (?, ?)", (name, balance) + ) self.connection.commit() def update_account(self, id, name, balance): - self.cursor.execute("UPDATE accounts SET name=?, balance=? WHERE id=?", (name, balance, id)) + self.cursor.execute( + "UPDATE accounts SET name=?, balance=? WHERE id=?", (name, balance, id) + ) self.connection.commit() def delete_account(self, id): From 9bfc887f15ccc9b283f984f37efde48c815805f4 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:58:00 +0000 Subject: [PATCH 33/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 6469eb1 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- machine_learning/machine_learning.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/machine_learning/machine_learning.py b/machine_learning/machine_learning.py index f53b8d14a..67f4caf10 100644 --- a/machine_learning/machine_learning.py +++ b/machine_learning/machine_learning.py @@ -1,19 +1,20 @@ -import pandas as pd import numpy as np +import pandas as pd from sklearn.linear_model import LinearRegression + class MachineLearning: def __init__(self): pass def train_model(self, data): - X = data[['feature1', 'feature2']] - y = data['target'] + X = data[["feature1", "feature2"]] + y = data["target"] model = LinearRegression() model.fit(X, y) return model def predict(self, model, data): - X = data[['feature1', 'feature2']] + X = data[["feature1", "feature2"]] y = model.predict(X) return y From b3e93d7a6884fe5ebdb1e1264411e413d2d2808b Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:59:09 +0000 Subject: [PATCH 34/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in af2c73c according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- logging/logging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/logging/logging.py b/logging/logging.py index 0db567ee3..dea11d2be 100644 --- a/logging/logging.py +++ b/logging/logging.py @@ -1,12 +1,13 @@ import logging + class Logging: def __init__(self): - self.logger = logging.getLogger('banking_network') + self.logger = logging.getLogger("banking_network") self.logger.setLevel(logging.DEBUG) def setup_logging(self): - formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') + formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") console_handler = logging.StreamHandler() console_handler.setLevel(logging.DEBUG) console_handler.setFormatter(formatter) From 48c09f7485dec7c98a15feb7cd79c5860c2f2a9f Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:00:27 +0000 Subject: [PATCH 35/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 383135d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- testing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing.py b/testing.py index c6db305da..c507e3c5d 100644 --- a/testing.py +++ b/testing.py @@ -1,8 +1,10 @@ import unittest + class Testing(unittest.TestCase): def test_something(self): self.assertTrue(True) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() From 35e090c304abfbc40223f44cc6d1e0d04e81780d Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:04:38 +0000 Subject: [PATCH 36/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 53d9e51 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- api/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/__init__.py b/api/__init__.py index f02c44442..e61ac4911 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1,10 +1,12 @@ from flask import Flask -from .endpoints import endpoints + from .authentication import jwt_manager +from .endpoints import endpoints + def create_app(): app = Flask(__name__) - app.config.from_object('config') - app.register_blueprint(endpoints, url_prefix='/api') + app.config.from_object("config") + app.register_blueprint(endpoints, url_prefix="/api") jwt_manager.init_app(app) return app From 52b21f404999ced1f3bd22b8f31f8e9159e0b928 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:05:22 +0000 Subject: [PATCH 37/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 9746187 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- api/endpoints.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/api/endpoints.py b/api/endpoints.py index 8deff8235..6bc4572c6 100644 --- a/api/endpoints.py +++ b/api/endpoints.py @@ -1,24 +1,28 @@ -from flask import Blueprint, request, jsonify +from flask import Blueprint, jsonify, request + from .authentication import jwt_required -from .serializers import UserSchema, TransactionSchema +from .serializers import TransactionSchema, UserSchema + +endpoints = Blueprint("endpoints", __name__) -endpoints = Blueprint('endpoints', __name__) -@endpoints.route('/users', methods=['POST']) +@endpoints.route("/users", methods=["POST"]) def create_user(): user_schema = UserSchema() user = user_schema.load(request.get_json()) # Create user in the database return user_schema.jsonify(user), 201 -@endpoints.route('/users/', methods=['GET']) + +@endpoints.route("/users/", methods=["GET"]) @jwt_required() def get_user(user_id): user = get_user_from_database(user_id) user_schema = UserSchema() return user_schema.jsonify(user) -@endpoints.route('/users/', methods=['PUT']) + +@endpoints.route("/users/", methods=["PUT"]) @jwt_required() def update_user(user_id): user = get_user_from_database(user_id) @@ -27,14 +31,16 @@ def update_user(user_id): # Update user in the database return user_schema.jsonify(user) -@endpoints.route('/users/', methods=['DELETE']) + +@endpoints.route("/users/", methods=["DELETE"]) @jwt_required() def delete_user(user_id): user = get_user_from_database(user_id) # Delete user from the database - return '', 204 + return "", 204 -@endpoints.route('/transactions', methods=['POST']) + +@endpoints.route("/transactions", methods=["POST"]) @jwt_required() def create_transaction(): transaction_schema = TransactionSchema() @@ -42,21 +48,24 @@ def create_transaction(): # Create transaction in the database return transaction_schema.jsonify(transaction), 201 -@endpoints.route('/transactions', methods=['GET']) + +@endpoints.route("/transactions", methods=["GET"]) @jwt_required() def get_transactions(): transactions = get_transactions_from_database() transaction_schema = TransactionSchema(many=True) return transaction_schema.jsonify(transactions) -@endpoints.route('/transactions/', methods=['GET']) + +@endpoints.route("/transactions/", methods=["GET"]) @jwt_required() def get_transaction(transaction_id): transaction = get_transaction_from_database(transaction_id) transaction_schema = TransactionSchema() return transaction_schema.jsonify(transaction) -@endpoints.route('/transactions/', methods=['PUT']) + +@endpoints.route("/transactions/", methods=["PUT"]) @jwt_required() def update_transaction(transaction_id): transaction = get_transaction_from_database(transaction_id) @@ -65,9 +74,10 @@ def update_transaction(transaction_id): # Update transaction in the database return transaction_schema.jsonify(transaction) -@endpoints.route('/transactions/', methods=['DELETE']) + +@endpoints.route("/transactions/", methods=["DELETE"]) @jwt_required() def delete_transaction(transaction_id): transaction = get_transaction_from_database(transaction_id) # Delete transaction from the database - return '', 204 + return "", 204 From 01da4bfbfb5e7981e62c8516f58bfa83d43cabff Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:06:36 +0000 Subject: [PATCH 38/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2e00c22 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- api/serializers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/serializers.py b/api/serializers.py index 881af2596..ad0d700fe 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,11 +1,13 @@ from marshmallow import Schema, fields + class UserSchema(Schema): id = fields.Int(dump_only=True) name = fields.Str(required=True) email = fields.Email(required=True) password = fields.Str(required=True, load_only=True) + class TransactionSchema(Schema): id = fields.Int(dump_only=True) user_id = fields.Int(required=True) From 537d2ac0c70e078777e5ca862c79c2fea9b283b2 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:07:24 +0000 Subject: [PATCH 39/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 3358225 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- api/test_endpoints.py | 136 +++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 74 deletions(-) diff --git a/api/test_endpoints.py b/api/test_endpoints.py index 805c982cc..864c6d238 100644 --- a/api/test_endpoints.py +++ b/api/test_endpoints.py @@ -1,7 +1,10 @@ import unittest + from app import create_app + from api.endpoints import endpoints -from api.serializers import UserSchema, TransactionSchema +from api.serializers import TransactionSchema, UserSchema + class TestEndpoints(unittest.TestCase): def setUp(self): @@ -16,11 +19,11 @@ def tearDown(self): def test_create_user(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - response = self.client.post('/api/users', json=user_data) + response = self.client.post("/api/users", json=user_data) self.assertEqual(response.status_code, 201) user_schema = UserSchema() user = user_schema.load(response.get_json()) @@ -28,54 +31,51 @@ def test_create_user(self): def test_get_user(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/users', json=user_data) - response = self.client.get('/api/users/1') + self.client.post("/api/users", json=user_data) + response = self.client.get("/api/users/1") self.assertEqual(response.status_code, 200) user_schema = UserSchema() user = user_schema.load(response.get_json()) - self.assertEqual(user.name, 'Test User') - self.assertEqual(user.email, 'test@example.com') + self.assertEqual(user.name, "Test User") + self.assertEqual(user.email, "test@example.com") def test_update_user(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/users', json=user_data) - user_data['name'] = 'Updated Test User' - response = self.client.put('/api/users/1', json=user_data) + self.client.post("/api/users", json=user_data) + user_data["name"] = "Updated Test User" + response = self.client.put("/api/users/1", json=user_data) self.assertEqual(response.status_code, 200) user_schema = UserSchema() user = user_schema.load(response.get_json()) - self.assertEqual(user.name, 'Updated Test User') + self.assertEqual(user.name, "Updated Test User") def test_delete_user(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/users', json=user_data) - response = self.client.delete('/api/users/1') + self.client.post("/api/users", json=user_data) + response = self.client.delete("/api/users/1") self.assertEqual(response.status_code, 204) def test_create_transaction(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' - } - self.client.post('/api/users', json=user_data) - transaction_data = { - 'user_id': 1, - 'amount': 100.0 + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - response = self.client.post('/api/transactions', json=transaction_data) + self.client.post("/api/users", json=user_data) + transaction_data = {"user_id": 1, "amount": 100.0} + response = self.client.post("/api/transactions", json=transaction_data) self.assertEqual(response.status_code, 201) transaction_schema = TransactionSchema() transaction = transaction_schema.load(response.get_json()) @@ -83,17 +83,14 @@ def test_create_transaction(self): def test_get_transactions(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password':'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/users', json=user_data) - transaction_data = { - 'user_id': 1, - 'amount': 100.0 - } - self.client.post('/api/transactions', json=transaction_data) - response = self.client.get('/api/transactions') + self.client.post("/api/users", json=user_data) + transaction_data = {"user_id": 1, "amount": 100.0} + self.client.post("/api/transactions", json=transaction_data) + response = self.client.get("/api/transactions") self.assertEqual(response.status_code, 200) transaction_schema = TransactionSchema(many=True) transactions = transaction_schema.load(response.get_json()) @@ -101,17 +98,14 @@ def test_get_transactions(self): def test_get_transaction(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' - } - self.client.post('/api/users', json=user_data) - transaction_data = { - 'user_id': 1, - 'amount': 100.0 + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/transactions', json=transaction_data) - response = self.client.get('/api/transactions/1') + self.client.post("/api/users", json=user_data) + transaction_data = {"user_id": 1, "amount": 100.0} + self.client.post("/api/transactions", json=transaction_data) + response = self.client.get("/api/transactions/1") self.assertEqual(response.status_code, 200) transaction_schema = TransactionSchema() transaction = transaction_schema.load(response.get_json()) @@ -119,18 +113,15 @@ def test_get_transaction(self): def test_update_transaction(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/users', json=user_data) - transaction_data = { - 'user_id': 1, - 'amount': 100.0 - } - self.client.post('/api/transactions', json=transaction_data) - transaction_data['amount'] = 200.0 - response = self.client.put('/api/transactions/1', json=transaction_data) + self.client.post("/api/users", json=user_data) + transaction_data = {"user_id": 1, "amount": 100.0} + self.client.post("/api/transactions", json=transaction_data) + transaction_data["amount"] = 200.0 + response = self.client.put("/api/transactions/1", json=transaction_data) self.assertEqual(response.status_code, 200) transaction_schema = TransactionSchema() transaction = transaction_schema.load(response.get_json()) @@ -138,15 +129,12 @@ def test_update_transaction(self): def test_delete_transaction(self): user_data = { - 'name': 'Test User', - 'email': 'test@example.com', - 'password': 'testpassword' - } - self.client.post('/api/users', json=user_data) - transaction_data = { - 'user_id': 1, - 'amount': 100.0 + "name": "Test User", + "email": "test@example.com", + "password": "testpassword", } - self.client.post('/api/transactions', json=transaction_data) - response = self.client.delete('/api/transactions/1') + self.client.post("/api/users", json=user_data) + transaction_data = {"user_id": 1, "amount": 100.0} + self.client.post("/api/transactions", json=transaction_data) + response = self.client.delete("/api/transactions/1") self.assertEqual(response.status_code, 204) From 4c4d0a4eca8583f3f293c509a0a3d9ea1af57bfa Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:10:26 +0000 Subject: [PATCH 40/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in d347349 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockchain/__init__.py b/blockchain/__init__.py index 2fe5e113f..112888f97 100644 --- a/blockchain/__init__.py +++ b/blockchain/__init__.py @@ -1,6 +1,6 @@ -from .pi_network import PiNetwork -from .ethereum import Ethereum from .bitcoin import Bitcoin from .block import Block from .chain import Blockchain +from .ethereum import Ethereum from .miner import Miner +from .pi_network import PiNetwork From 3c441256b1ac6169c3e0ccefed5bcde929c312fb Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:11:14 +0000 Subject: [PATCH 41/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in c5cbe89 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/block.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blockchain/block.py b/blockchain/block.py index ca6f44246..7945ecbae 100644 --- a/blockchain/block.py +++ b/blockchain/block.py @@ -1,6 +1,7 @@ import hashlib import time + class Block: def __init__(self, index, previous_hash, timestamp, data, hash): self.index = index @@ -12,13 +13,13 @@ def __init__(self, index, previous_hash, timestamp, data, hash): @staticmethod def calculate_hash(index, previous_hash, timestamp, data): value = str(index) + str(previous_hash) + str(timestamp) + str(data) - return hashlib.sha256(value.encode('utf-8')).hexdigest() + return hashlib.sha256(value.encode("utf-8")).hexdigest() def __str__(self): - return 'Block: {index}, Previous Hash: {previous_hash}, Timestamp: {timestamp}, Data: {data}, Hash: {hash}'.format( + return "Block: {index}, Previous Hash: {previous_hash}, Timestamp: {timestamp}, Data: {data}, Hash: {hash}".format( index=self.index, previous_hash=self.previous_hash, timestamp=self.timestamp, data=self.data, - hash=self.hash + hash=self.hash, ) From 34420a9a9eb0680432e396af8ebe19d10759c6f0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:53:25 +0000 Subject: [PATCH 42/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 1fd4140 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/chain.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/blockchain/chain.py b/blockchain/chain.py index ad5ad80d5..ee2bc218f 100644 --- a/blockchain/chain.py +++ b/blockchain/chain.py @@ -1,23 +1,35 @@ import hashlib + class Blockchain: def __init__(self): self.chain = [self.create_genesis_block()] self.difficulty = 2 def create_genesis_block(self): - return Block(0, '0' * 64, int(time.time()), 'Genesis Block', self.calculate_hash(0, '0' * 64, int(time.time()), 'Genesis Block')) + return Block( + 0, + "0" * 64, + int(time.time()), + "Genesis Block", + self.calculate_hash(0, "0" * 64, int(time.time()), "Genesis Block"), + ) def calculate_hash(self, index, previous_hash, timestamp, data): value = str(index) + str(previous_hash) + str(timestamp) + str(data) - return hashlib.sha256(value.encode('utf-8')).hexdigest() + return hashlib.sha256(value.encode("utf-8")).hexdigest() def is_chain_valid(self, chain): for i in range(1, len(chain)): current_block = chain[i] previous_block = chain[i - 1] - if current_block.hash != self.calculate_hash(current_block.index, current_block.previous_hash, current_block.timestamp, current_block.data): + if current_block.hash != self.calculate_hash( + current_block.index, + current_block.previous_hash, + current_block.timestamp, + current_block.data, + ): return False if current_block.previous_hash != previous_block.hash: @@ -26,8 +38,15 @@ def is_chain_valid(self, chain): return True def add_block(self, data): - new_block = Block(len(self.chain), self.chain[-1].hash, int(time.time()), data, None) - new_block.hash = self.calculate_hash(new_block.index, new_block.previous_hash, new_block.timestamp, new_block.data) + new_block = Block( + len(self.chain), self.chain[-1].hash, int(time.time()), data, None + ) + new_block.hash = self.calculate_hash( + new_block.index, + new_block.previous_hash, + new_block.timestamp, + new_block.data, + ) self.chain.append(new_block) def replace_chain(self, chain): From 6d6bdca1d1507dba670ca96c2e47b732d626c0f5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 13:56:12 +0000 Subject: [PATCH 43/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 06f5ed4 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/miner.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/blockchain/miner.py b/blockchain/miner.py index 2a0a17daf..024156d65 100644 --- a/blockchain/miner.py +++ b/blockchain/miner.py @@ -1,6 +1,8 @@ import time + from blockchain.block import Blockchain + class Miner: def __init__(self, blockchain): self.blockchain = blockchain @@ -9,12 +11,12 @@ def mine_block(self, data): while True: if self.blockchain.is_chain_valid(self.blockchain.chain): self.blockchain.add_block(data) - print('Block successfully mined!') - print('Proof of work: {}'.format(self.blockchain.chain[-1].hash)) + print("Block successfully mined!") + print("Proof of work: {}".format(self.blockchain.chain[-1].hash)) break else: - print('Block not mined. Invalid chain.') + print("Block not mined. Invalid chain.") self.blockchain.chain = [self.blockchain.create_genesis_block()] self.blockchain.difficulty += 1 - print('New difficulty: {}'.format(self.blockchain.difficulty)) + print("New difficulty: {}".format(self.blockchain.difficulty)) time.sleep(1) From 7bce9ca76845ee780b2329274bc3d262577448e8 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:00:45 +0000 Subject: [PATCH 44/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 14e3e1d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/test/test_blockchain.py | 50 +++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/blockchain/test/test_blockchain.py b/blockchain/test/test_blockchain.py index bd7e51ad8..d3217a024 100644 --- a/blockchain/test/test_blockchain.py +++ b/blockchain/test/test_blockchain.py @@ -1,6 +1,8 @@ import unittest + from blockchain import Blockchain + class TestBlockchain(unittest.TestCase): def setUp(self): self.blockchain = Blockchain() @@ -8,40 +10,66 @@ def setUp(self): def test_create_genesis_block(self): genesis_block = self.blockchain.create_genesis_block() self.assertEqual(genesis_block.index, 0) - self.assertEqual(genesis_block.previous_hash, '0' * 64) + self.assertEqual(genesis_block.previous_hash, "0" * 64) self.assertIsNotNone(genesis_block.timestamp) - self.assertEqual(genesis_block.data, 'Genesis Block') - self.assertEqual(genesis_block.hash, '0' * 64) + self.assertEqual(genesis_block.data, "Genesis Block") + self.assertEqual(genesis_block.hash, "0" * 64) def test_calculate_hash(self): block = self.blockchain.create_genesis_block() - block.data = 'New Data' + block.data = "New Data" block.hash = None - calculated_hash = self.blockchain.calculate_hash(block.index, block.previous_hash, block.timestamp, block.data) - self.assertEqual(calculated_hash, '0' * 64) + calculated_hash = self.blockchain.calculate_hash( + block.index, block.previous_hash, block.timestamp, block.data + ) + self.assertEqual(calculated_hash, "0" * 64) def test_is_chain_valid(self): self.assertTrue(self.blockchain.is_chain_valid(self.blockchain.chain)) invalid_chain = self.blockchain.chain[:-1] - invalid_chain.append(Block(len(invalid_chain), invalid_chain[-1].hash, int(time.time()), 'Invalid Data', None)) + invalid_chain.append( + Block( + len(invalid_chain), + invalid_chain[-1].hash, + int(time.time()), + "Invalid Data", + None, + ) + ) self.assertFalse(self.blockchain.is_chain_valid(invalid_chain)) def test_add_block(self): - self.blockchain.add_block('Test Data') + self.blockchain.add_block("Test Data") self.assertEqual(len(self.blockchain.chain), 2) - self.assertEqual(self.blockchain.chain[-1].data, 'Test Data') + self.assertEqual(self.blockchain.chain[-1].data, "Test Data") def test_replace_chain(self): self.blockchain.replace_chain(self.blockchain.chain[:-1]) self.assertEqual(len(self.blockchain.chain), 1) invalid_chain = self.blockchain.chain[:-1] - invalid_chain.append(Block(len(invalid_chain), invalid_chain[-1].hash, int(time.time()), 'Invalid Data', None)) + invalid_chain.append( + Block( + len(invalid_chain), + invalid_chain[-1].hash, + int(time.time()), + "Invalid Data", + None, + ) + ) self.blockchain.replace_chain(invalid_chain) self.assertFalse(self.blockchain.is_chain_valid(self.blockchain.chain)) valid_chain = self.blockchain.chain[:-1] - valid_chain.append(Block(len(valid_chain), valid_chain[-1].hash, int(time.time()), 'Valid Data', None)) + valid_chain.append( + Block( + len(valid_chain), + valid_chain[-1].hash, + int(time.time()), + "Valid Data", + None, + ) + ) self.blockchain.replace_chain(valid_chain) self.assertTrue(self.blockchain.is_chain_valid(self.blockchain.chain)) From ecf25cd9108f4b2b720e131af72eff704303edfa Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:11:35 +0000 Subject: [PATCH 45/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 0b45323 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- banking/account_management.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/banking/account_management.py b/banking/account_management.py index 1fe44c0e3..4a41344cd 100644 --- a/banking/account_management.py +++ b/banking/account_management.py @@ -3,6 +3,7 @@ import logging from typing import Dict + def create_account(account_type: str, balance: float, customer_id: int) -> Dict: """ Create a new account for a customer. @@ -18,22 +19,23 @@ def create_account(account_type: str, balance: float, customer_id: int) -> Dict: # implementation logging.info(f"Creating account for customer {customer_id}") # Validate input parameters - if account_type not in ['checking', 'savings']: + if account_type not in ["checking", "savings"]: raise ValueError("Invalid account type") if balance < 0: raise ValueError("Balance cannot be negative") # Create account and store it in a database or in-memory data structure account = { - 'id': generate_unique_id(), - 'type': account_type, - 'balance': balance, - 'customer_id': customer_id + "id": generate_unique_id(), + "type": account_type, + "balance": balance, + "customer_id": customer_id, } # Return the account information return account + def update_account(account_id: int, account_type: str, balance: float) -> bool: """ Update an existing account. @@ -49,7 +51,7 @@ def update_account(account_id: int, account_type: str, balance: float) -> bool: # implementation logging.info(f"Updating account {account_id}") # Validate input parameters - if account_type not in ['checking', 'savings']: + if account_type not in ["checking", "savings"]: raise ValueError("Invalid account type") if balance < 0: raise ValueError("Balance cannot be negative") @@ -58,8 +60,8 @@ def update_account(account_id: int, account_type: str, balance: float) -> bool: account = get_account_by_id(account_id) # Update the account information - account['type'] = account_type - account['balance'] = balance + account["type"] = account_type + account["balance"] = balance # Save the updated account back to the database or in-memory data structure save_account(account) @@ -67,6 +69,7 @@ def update_account(account_id: int, account_type: str, balance: float) -> bool: # Return True to indicate success return True + def delete_account(account_id: int) -> bool: """ Delete an account. From 646818cf6c70e519a7a356d1d4db3cbab0c097c7 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:29:49 +0700 Subject: [PATCH 46/89] Create quantum_encryption.py --- quantum_module/quantum_encryption.py | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 quantum_module/quantum_encryption.py diff --git a/quantum_module/quantum_encryption.py b/quantum_module/quantum_encryption.py new file mode 100644 index 000000000..8a2cd47c6 --- /dev/null +++ b/quantum_module/quantum_encryption.py @@ -0,0 +1,46 @@ +# Import necessary libraries +import numpy as np +from qiskit import QuantumCircuit, execute +from qiskit.providers.aer import AerSimulator + +# Define a function to generate a quantum key +def generate_quantum_key(size): + # Create a quantum circuit with two qubits + qc = QuantumCircuit(2) + + # Apply Hadamard gates to both qubits + qc.h(0) + qc.h(1) + + # Measure the qubits to generate a random key + qc.measure_all() + + # Execute the circuit on a simulator + simulator = AerSimulator() + job = execute(qc, simulator, shots=1) + result = job.result() + key = result.get_counts(qc) + + # Convert the key to a binary string + key_str = ''.join(format(x, 'b') for x in key) + + return key_str[:size] + +# Define a function to encrypt data using quantum encryption +def encrypt_data(plain_text, key): + # Convert the plain text to a binary string + plain_text_bin = ''.join(format(ord(c), '08b') for c in plain_text) + + # Encrypt the plain text using the quantum key + cipher_text_bin = ''.join(str(int(plain_text_bin[i]) ^ int(key[i % len(key)])) for i in range(len(plain_text_bin))) + + # Convert the cipher text back to a string + cipher_text = ''.join(chr(int(cipher_text_bin[i*8:i*8+8], 2)) for i in range(len(cipher_text_bin)//8)) + + return cipher_text + +# Example usage +key = generate_quantum_key(256) +plain_text = "This is a secret message" +cipher_text = encrypt_data(plain_text, key) +print("Encrypted text:", cipher_text) From 0caad04628b3612336376053993d039a232f3271 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:30:10 +0000 Subject: [PATCH 47/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 646818c according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- quantum_module/quantum_encryption.py | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/quantum_module/quantum_encryption.py b/quantum_module/quantum_encryption.py index 8a2cd47c6..394afc07b 100644 --- a/quantum_module/quantum_encryption.py +++ b/quantum_module/quantum_encryption.py @@ -4,41 +4,53 @@ from qiskit.providers.aer import AerSimulator # Define a function to generate a quantum key + + def generate_quantum_key(size): # Create a quantum circuit with two qubits qc = QuantumCircuit(2) - + # Apply Hadamard gates to both qubits qc.h(0) qc.h(1) - + # Measure the qubits to generate a random key qc.measure_all() - + # Execute the circuit on a simulator simulator = AerSimulator() job = execute(qc, simulator, shots=1) result = job.result() key = result.get_counts(qc) - + # Convert the key to a binary string - key_str = ''.join(format(x, 'b') for x in key) - + key_str = "".join(format(x, "b") for x in key) + return key_str[:size] + # Define a function to encrypt data using quantum encryption + + def encrypt_data(plain_text, key): # Convert the plain text to a binary string - plain_text_bin = ''.join(format(ord(c), '08b') for c in plain_text) - + plain_text_bin = "".join(format(ord(c), "08b") for c in plain_text) + # Encrypt the plain text using the quantum key - cipher_text_bin = ''.join(str(int(plain_text_bin[i]) ^ int(key[i % len(key)])) for i in range(len(plain_text_bin))) - + cipher_text_bin = "".join( + str(int(plain_text_bin[i]) ^ int(key[i % len(key)])) + for i in range(len(plain_text_bin)) + ) + # Convert the cipher text back to a string - cipher_text = ''.join(chr(int(cipher_text_bin[i*8:i*8+8], 2)) for i in range(len(cipher_text_bin)//8)) - + cipher_text = "".join( + chr(int(cipher_text_bin[i * 8 : i * 8 + 8], 2)) + for i in range(len(cipher_text_bin) // 8) + ) + return cipher_text + # Example usage key = generate_quantum_key(256) plain_text = "This is a secret message" From 22383ada3f2854f6f2a728fd4c3230945f5b2798 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:30:40 +0700 Subject: [PATCH 48/89] Create quantum_optimization.py --- quantum_module/quantum_optimization.py | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 quantum_module/quantum_optimization.py diff --git a/quantum_module/quantum_optimization.py b/quantum_module/quantum_optimization.py new file mode 100644 index 000000000..c5832a997 --- /dev/null +++ b/quantum_module/quantum_optimization.py @@ -0,0 +1,43 @@ +# Import necessary libraries +import numpy as np +from qiskit import QuantumCircuit, execute +from qiskit.providers.aer import AerSimulator +from qiskit.optimization import QuadraticProgram + +# Define a function to optimize a portfolio using quantum computing +def optimize_portfolio(stocks, weights, risk_tolerance): + # Define the quadratic program + qp = QuadraticProgram() + qp.binary_var_list(stocks, name='x') + qp.minimize(linear={stocks[i]: weights[i] for i in range(len(stocks))}) + qp.subject_to(LinearConstraint(sense='LE', rhs=risk_tolerance, coeffs={stocks[i]: weights[i] for i in range(len(stocks))})) + + # Convert the quadratic program to a QUBO problem + qubo = qp.to_qubo() + + # Create a quantum circuit to solve the QUBO problem + qc = QuantumCircuit(len(stocks)) + qc.h(range(len(stocks))) + qc.barrier() + qc.x(range(len(stocks))) + qc.barrier() + qc.measure_all() + + # Execute the circuit on a simulator + simulator = AerSimulator() + job = execute(qc, simulator, shots=1000) + result = job.result() + counts = result.get_counts(qc) + + # Extract the optimal solution from the counts + optimal_solution = max(counts, key=counts.get) + optimal_portfolio = [stocks[i] for i, x in enumerate(optimal_solution) if x == '1'] + + return optimal_portfolio + +# Example usage +stocks = ['AAPL', 'GOOG', 'MSFT'] +weights = [0.3, 0.4, 0.3] +risk_tolerance = 0.5 +optimal_portfolio = optimize_portfolio(stocks, weights, risk_tolerance) +print("Optimal portfolio:", optimal_portfolio) From 952f6332567e3bee160b79e9fa602a45edc51818 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:31:03 +0000 Subject: [PATCH 49/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 22383ad according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- quantum_module/quantum_optimization.py | 29 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/quantum_module/quantum_optimization.py b/quantum_module/quantum_optimization.py index c5832a997..20fb7b73e 100644 --- a/quantum_module/quantum_optimization.py +++ b/quantum_module/quantum_optimization.py @@ -1,20 +1,28 @@ # Import necessary libraries import numpy as np from qiskit import QuantumCircuit, execute -from qiskit.providers.aer import AerSimulator from qiskit.optimization import QuadraticProgram +from qiskit.providers.aer import AerSimulator # Define a function to optimize a portfolio using quantum computing + + def optimize_portfolio(stocks, weights, risk_tolerance): # Define the quadratic program qp = QuadraticProgram() - qp.binary_var_list(stocks, name='x') + qp.binary_var_list(stocks, name="x") qp.minimize(linear={stocks[i]: weights[i] for i in range(len(stocks))}) - qp.subject_to(LinearConstraint(sense='LE', rhs=risk_tolerance, coeffs={stocks[i]: weights[i] for i in range(len(stocks))})) - + qp.subject_to( + LinearConstraint( + sense="LE", + rhs=risk_tolerance, + coeffs={stocks[i]: weights[i] for i in range(len(stocks))}, + ) + ) + # Convert the quadratic program to a QUBO problem qubo = qp.to_qubo() - + # Create a quantum circuit to solve the QUBO problem qc = QuantumCircuit(len(stocks)) qc.h(range(len(stocks))) @@ -22,21 +30,22 @@ def optimize_portfolio(stocks, weights, risk_tolerance): qc.x(range(len(stocks))) qc.barrier() qc.measure_all() - + # Execute the circuit on a simulator simulator = AerSimulator() job = execute(qc, simulator, shots=1000) result = job.result() counts = result.get_counts(qc) - + # Extract the optimal solution from the counts optimal_solution = max(counts, key=counts.get) - optimal_portfolio = [stocks[i] for i, x in enumerate(optimal_solution) if x == '1'] - + optimal_portfolio = [stocks[i] for i, x in enumerate(optimal_solution) if x == "1"] + return optimal_portfolio + # Example usage -stocks = ['AAPL', 'GOOG', 'MSFT'] +stocks = ["AAPL", "GOOG", "MSFT"] weights = [0.3, 0.4, 0.3] risk_tolerance = 0.5 optimal_portfolio = optimize_portfolio(stocks, weights, risk_tolerance) From 0f6e0b6b3b6deb601eafae6b211a85483af528e6 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:31:54 +0700 Subject: [PATCH 50/89] Create quantum_simulation.py --- quantum_module/quantum_simulation.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 quantum_module/quantum_simulation.py diff --git a/quantum_module/quantum_simulation.py b/quantum_module/quantum_simulation.py new file mode 100644 index 000000000..36a5cc522 --- /dev/null +++ b/quantum_module/quantum_simulation.py @@ -0,0 +1,37 @@ +# Import necessary libraries +import numpy as np +from qiskit import QuantumCircuit, execute +from qiskit.providers.aer import AerSimulator + +# Define a function to simulate a complex financial scenario using quantum computing +def simulate_financial_scenario(initial_investment, interest_rate, time_steps): + # Create a quantum circuit to simulate the financial scenario + qc = QuantumCircuit(1) + qc.h(0) + qc.barrier() + for i in range(time_steps): + qc.rx(np.arcsin(interest_rate), 0) + qc.barrier() + qc.measure_all() + + # Execute the circuit on a simulator + simulator = AerSimulator() + job = execute(qc, simulator, shots=1000) + result = job.result() + counts = result.get_counts(qc) + + # Extract the final investment from the counts + final_investment = initial_investment * (1 + interest_rate) ** time_steps + for i in range(time_steps): + final_investment *= (1 + interest_rate) + final_investment = final_investment / 1000 + final_investment = sum(counts[x] * final_investment for x in counts) + + return final_investment + +# Example usage +initial_investment = 1000 +interest_rate = 0.05 +time_steps = 10 +final_investment = simulate_financial_scenario(initial_investment, interest_rate, time_steps) +print("Final investment:", final_investment) From 4434d18135b64892958da5bd8abfde330b1c5774 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:33:42 +0000 Subject: [PATCH 51/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 0f6e0b6 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- quantum_module/quantum_simulation.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/quantum_module/quantum_simulation.py b/quantum_module/quantum_simulation.py index 36a5cc522..dfc6f3614 100644 --- a/quantum_module/quantum_simulation.py +++ b/quantum_module/quantum_simulation.py @@ -4,6 +4,8 @@ from qiskit.providers.aer import AerSimulator # Define a function to simulate a complex financial scenario using quantum computing + + def simulate_financial_scenario(initial_investment, interest_rate, time_steps): # Create a quantum circuit to simulate the financial scenario qc = QuantumCircuit(1) @@ -13,25 +15,28 @@ def simulate_financial_scenario(initial_investment, interest_rate, time_steps): qc.rx(np.arcsin(interest_rate), 0) qc.barrier() qc.measure_all() - + # Execute the circuit on a simulator simulator = AerSimulator() job = execute(qc, simulator, shots=1000) result = job.result() counts = result.get_counts(qc) - + # Extract the final investment from the counts final_investment = initial_investment * (1 + interest_rate) ** time_steps for i in range(time_steps): - final_investment *= (1 + interest_rate) + final_investment *= 1 + interest_rate final_investment = final_investment / 1000 final_investment = sum(counts[x] * final_investment for x in counts) - + return final_investment + # Example usage initial_investment = 1000 interest_rate = 0.05 time_steps = 10 -final_investment = simulate_financial_scenario(initial_investment, interest_rate, time_steps) +final_investment = simulate_financial_scenario( + initial_investment, interest_rate, time_steps +) print("Final investment:", final_investment) From 9ba40d41df32a0fb85e06b04331a310307456a07 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:36:33 +0700 Subject: [PATCH 52/89] Create blockchain.py --- blockchain/blockchain.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 blockchain/blockchain.py diff --git a/blockchain/blockchain.py b/blockchain/blockchain.py new file mode 100644 index 000000000..f56ac485b --- /dev/null +++ b/blockchain/blockchain.py @@ -0,0 +1,40 @@ +import hashlib +import time + +class Block: + def __init__(self, index, previous_hash, timestamp, data, hash): + self.index = index + self.previous_hash = previous_hash + self.timestamp = timestamp + self.data = data + self.hash = hash + +class Blockchain: + def __init__(self): + self.chain = [self.create_genesis_block()] + self.difficulty = 5 + + def create_genesis_block(self): + return Block(0, "0" * 64, int(time.time()), "Genesis Block", self.calculate_hash(0, "0" * 64, int(time.time()), "Genesis Block")) + + def calculate_hash(self, index, previous_hash, timestamp, data): + value = str(index) + str(previous_hash) + str(timestamp) + str(data) + return hashlib.sha256(value.encode('utf-8')).hexdigest() + + def add_block(self, block): + block.previous_hash = self.chain[-1].hash + block.hash = self.calculate_hash(block.index, block.previous_hash, block.timestamp, block.data) + self.chain.append(block) + + def is_valid(self): + for i in range(1, len(self.chain)): + current_block = self.chain[i] + previous_block = self.chain[i - 1] + + if current_block.hash != self.calculate_hash(current_block.index, current_block.previous_hash, current_block.timestamp, current_block.data): + return False + + if previous_block.hash != current_block.previous_hash: + return False + + return True From d42f9e47b3a8d1169b3033c83ae8410981acbeb0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:36:59 +0000 Subject: [PATCH 53/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 9ba40d4 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/blockchain.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/blockchain/blockchain.py b/blockchain/blockchain.py index f56ac485b..90f0fb863 100644 --- a/blockchain/blockchain.py +++ b/blockchain/blockchain.py @@ -1,6 +1,7 @@ import hashlib import time + class Block: def __init__(self, index, previous_hash, timestamp, data, hash): self.index = index @@ -9,21 +10,30 @@ def __init__(self, index, previous_hash, timestamp, data, hash): self.data = data self.hash = hash + class Blockchain: def __init__(self): self.chain = [self.create_genesis_block()] self.difficulty = 5 def create_genesis_block(self): - return Block(0, "0" * 64, int(time.time()), "Genesis Block", self.calculate_hash(0, "0" * 64, int(time.time()), "Genesis Block")) + return Block( + 0, + "0" * 64, + int(time.time()), + "Genesis Block", + self.calculate_hash(0, "0" * 64, int(time.time()), "Genesis Block"), + ) def calculate_hash(self, index, previous_hash, timestamp, data): value = str(index) + str(previous_hash) + str(timestamp) + str(data) - return hashlib.sha256(value.encode('utf-8')).hexdigest() + return hashlib.sha256(value.encode("utf-8")).hexdigest() def add_block(self, block): block.previous_hash = self.chain[-1].hash - block.hash = self.calculate_hash(block.index, block.previous_hash, block.timestamp, block.data) + block.hash = self.calculate_hash( + block.index, block.previous_hash, block.timestamp, block.data + ) self.chain.append(block) def is_valid(self): @@ -31,7 +41,12 @@ def is_valid(self): current_block = self.chain[i] previous_block = self.chain[i - 1] - if current_block.hash != self.calculate_hash(current_block.index, current_block.previous_hash, current_block.timestamp, current_block.data): + if current_block.hash != self.calculate_hash( + current_block.index, + current_block.previous_hash, + current_block.timestamp, + current_block.data, + ): return False if previous_block.hash != current_block.previous_hash: From 388f2b43fb88bb0988d9c41ebe6e81c76cff8372 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:37:17 +0700 Subject: [PATCH 54/89] Create transaction.py --- blockchain/transaction.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 blockchain/transaction.py diff --git a/blockchain/transaction.py b/blockchain/transaction.py new file mode 100644 index 000000000..79eb547a5 --- /dev/null +++ b/blockchain/transaction.py @@ -0,0 +1,8 @@ +class Transaction: + def __init__(self, sender, receiver, amount): + self.sender = sender + self.receiver = receiver + self.amount = amount + + def to_string(self): + return "Sender: " + self.sender + ", Receiver: " + self.receiver + ", Amount: " + str(self.amount) From 46915ef9d739c661aea2a8a1e2244c7e7d9a8665 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:37:40 +0000 Subject: [PATCH 55/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 388f2b4 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/transaction.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blockchain/transaction.py b/blockchain/transaction.py index 79eb547a5..0a49fcf79 100644 --- a/blockchain/transaction.py +++ b/blockchain/transaction.py @@ -5,4 +5,11 @@ def __init__(self, sender, receiver, amount): self.amount = amount def to_string(self): - return "Sender: " + self.sender + ", Receiver: " + self.receiver + ", Amount: " + str(self.amount) + return ( + "Sender: " + + self.sender + + ", Receiver: " + + self.receiver + + ", Amount: " + + str(self.amount) + ) From c635fff2cdf7589046a0588638c094ef7d6d97df Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:37:49 +0700 Subject: [PATCH 56/89] Create wallet.py --- blockchain/wallet.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 blockchain/wallet.py diff --git a/blockchain/wallet.py b/blockchain/wallet.py new file mode 100644 index 000000000..0435c425d --- /dev/null +++ b/blockchain/wallet.py @@ -0,0 +1,14 @@ +import hashlib +import time + +class Wallet: + def __init__(self): + self.private_key = hashlib.sha256(str(time.time()).encode('utf-8')).hexdigest() + self.public_key = hashlib.sha256(self.private_key.encode('utf-8')).hexdigest() + + def generate_address(self): + return hashlib.sha256(self.public_key.encode('utf-8')).hexdigest() + + def send_transaction(self, recipient, amount): + transaction = Transaction(self.generate_address(), recipient, amount) + return transaction From 0ad693fe5fcd02886a21d4cd438c062455d90848 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:38:11 +0000 Subject: [PATCH 57/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in c635fff according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- blockchain/wallet.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blockchain/wallet.py b/blockchain/wallet.py index 0435c425d..b23d52db9 100644 --- a/blockchain/wallet.py +++ b/blockchain/wallet.py @@ -1,13 +1,14 @@ import hashlib import time + class Wallet: def __init__(self): - self.private_key = hashlib.sha256(str(time.time()).encode('utf-8')).hexdigest() - self.public_key = hashlib.sha256(self.private_key.encode('utf-8')).hexdigest() + self.private_key = hashlib.sha256(str(time.time()).encode("utf-8")).hexdigest() + self.public_key = hashlib.sha256(self.private_key.encode("utf-8")).hexdigest() def generate_address(self): - return hashlib.sha256(self.public_key.encode('utf-8')).hexdigest() + return hashlib.sha256(self.public_key.encode("utf-8")).hexdigest() def send_transaction(self, recipient, amount): transaction = Transaction(self.generate_address(), recipient, amount) From 2be8c789cf6853a62c549a265fd810e081b22e38 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:41:01 +0700 Subject: [PATCH 58/89] Create contract.py --- smart_contracts/contract.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 smart_contracts/contract.py diff --git a/smart_contracts/contract.py b/smart_contracts/contract.py new file mode 100644 index 000000000..589a4e277 --- /dev/null +++ b/smart_contracts/contract.py @@ -0,0 +1,31 @@ +import hashlib +import time +from transaction import Transaction + +class Contract: + def __init__(self, address, code): + self.address = address + self.code = code + self.state = {} + + def execute(self, transaction): + # Check if the transaction sender has enough funds + if self.state.get(transaction.sender, 0) < transaction.amount: + return False + + # Execute the contract code + code_output = eval(self.code) + + # Update the contract state + self.state[transaction.receiver] = self.state.get(transaction.receiver, 0) + transaction.amount + self.state[transaction.sender] = self.state.get(transaction.sender, 0) - transaction.amount + + # Return the output of the contract code + return code_output + + def to_dict(self): + return { + 'address': self.address, + 'code': self.code, + 'state': self.state + } From fba7ed201a8586c8fe34d5763e3dbdd85d12bb12 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:41:22 +0000 Subject: [PATCH 59/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2be8c78 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- smart_contracts/contract.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/smart_contracts/contract.py b/smart_contracts/contract.py index 589a4e277..7c011fc33 100644 --- a/smart_contracts/contract.py +++ b/smart_contracts/contract.py @@ -1,7 +1,9 @@ import hashlib import time + from transaction import Transaction + class Contract: def __init__(self, address, code): self.address = address @@ -17,15 +19,15 @@ def execute(self, transaction): code_output = eval(self.code) # Update the contract state - self.state[transaction.receiver] = self.state.get(transaction.receiver, 0) + transaction.amount - self.state[transaction.sender] = self.state.get(transaction.sender, 0) - transaction.amount + self.state[transaction.receiver] = ( + self.state.get(transaction.receiver, 0) + transaction.amount + ) + self.state[transaction.sender] = ( + self.state.get(transaction.sender, 0) - transaction.amount + ) # Return the output of the contract code return code_output def to_dict(self): - return { - 'address': self.address, - 'code': self.code, - 'state': self.state - } + return {"address": self.address, "code": self.code, "state": self.state} From e65ed48a3119517c4c135d1dd11e88462763b632 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:46:16 +0700 Subject: [PATCH 60/89] Create communication.py --- network/communication.py | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 network/communication.py diff --git a/network/communication.py b/network/communication.py new file mode 100644 index 000000000..a5d98ef28 --- /dev/null +++ b/network/communication.py @@ -0,0 +1,51 @@ +import json +import requests +import websockets + +def send_http_request(url, method, headers=None, data=None): + """ + Sends an HTTP request to the specified URL using the specified method, headers, and data. + """ + if headers is None: + headers = {} + + if method == "GET": + response = requests.get(url, headers=headers, data=data) + elif method == "POST": + response = requests.post(url, headers=headers, data=json.dumps(data)) + elif method == "PUT": + response = requests.put(url, headers=headers, data=json.dumps(data)) + elif method == "DELETE": +response = requests.delete(url, headers=headers, data=data) + else: + raise ValueError("Invalid HTTP method") + + if response.status_code != 200: + raise Exception("HTTP request failed with status code {}".format(response.status_code)) + + return response.json() + +def send_websocket_message(websocket, message): + """ + Sends a message over a WebSocket connection. + """ + websocket.send(json.dumps(message)) + +def receive_websocket_message(websocket): + """ + Receives a message over a WebSocket connection. + """ + return json.loads(websocket.recv()) + +def create_websocket_connection(url): + """ + Creates a new WebSocket connection to the specified URL. + """ + websocket = websockets.connect(url) + return websocket + +def close_websocket_connection(websocket): + """ + Closes the specified WebSocket connection. + """ + websocket.close() From 371383a2bbf98ad3d649e1f6c27aafe3a5147a66 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:48:40 +0700 Subject: [PATCH 61/89] Create ai.py --- ai/ai.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ai/ai.py diff --git a/ai/ai.py b/ai/ai.py new file mode 100644 index 000000000..338a2be76 --- /dev/null +++ b/ai/ai.py @@ -0,0 +1,43 @@ +import numpy as np +import tensorflow as tf +from tensorflow import keras + +class AI: + def __init__(self, input_shape, output_shape, hidden_layers=None, activation_function=tf.nn.relu): + """ + Initializes the AI class with the specified input and output shapes, and optional hidden layer sizes and activation function. + """ + self.input_shape = input_shape + self.output_shape = output_shape + self.hidden_layers = hidden_layers + self.activation_function = activation_function + + self.model = None + + def build_model(self): + """ + Builds the AI model using the specified input and output shapes, hidden layer sizes, and activation function. + """ + inputs = keras.Input(shape=self.input_shape) + x = inputs + + if self.hidden_layers is not None: + for hidden_layer in self.hidden_layers: + x = keras.layers.Dense(hidden_layer, activation=self.activation_function)(x) + + outputs = keras.layers.Dense(self.output_shape)(x) + + self.model = keras.Model(inputs=inputs, outputs=outputs) + + def train(self, x_train, y_train, epochs=10, batch_size=32): + """ + Trains the AI model using the specified training data, number of epochs, and batch size. + """ + self.model.compile(optimizer="adam", loss="mse") + self.model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size) + + def predict(self, x): + """ + Makes predictions using the AI model for the specified input data. + """ + return self.model.predict(x) From 72d321ddcc610cc3a47c66809a186b35c340b3c8 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:49:30 +0700 Subject: [PATCH 62/89] Create data_processing.py --- ai/data_processing.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ai/data_processing.py diff --git a/ai/data_processing.py b/ai/data_processing.py new file mode 100644 index 000000000..87cff1092 --- /dev/null +++ b/ai/data_processing.py @@ -0,0 +1,33 @@ +import pandas as pd +import numpy as np + +def preprocess_data(data): + """ + Preprocesses the specified data by cleaning, transforming, and scaling it. + """ + # Clean missing values + data = data.dropna() + + # Transform categorical variables to numerical variables + data = pd.get_dummies(data) + + # Scale numerical variables to have zero mean and unit variance + scaler = StandardScaler() + data = pd.DataFrame(scaler.fit_transform(data), columns=data.columns) + + return data + +def split_data(data, test_size=0.2): + """ + Splits the specified data into training and testing sets. + """ + np.random.seed(42) + shuffled_index = np.random.permutation(len(data)) + test_set_size = int(len(data) * test_size) + test_indices = shuffled_index[:test_set_size] + train_indices = shuffled_index[test_set_size:] + + train_data = data.iloc[train_indices] + test_data = data.iloc[test_indices] + + return train_data, test_data From c7fa6f00348d1796b064d50f599adeb113b6956d Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:49:50 +0000 Subject: [PATCH 63/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 72d321d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- ai/data_processing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ai/data_processing.py b/ai/data_processing.py index 87cff1092..77b3e51d9 100644 --- a/ai/data_processing.py +++ b/ai/data_processing.py @@ -1,5 +1,6 @@ -import pandas as pd import numpy as np +import pandas as pd + def preprocess_data(data): """ @@ -17,6 +18,7 @@ def preprocess_data(data): return data + def split_data(data, test_size=0.2): """ Splits the specified data into training and testing sets. From 9eda8f70720223404c0218c28c40d126e8912ccf Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:50:20 +0700 Subject: [PATCH 64/89] Delete banking/banking directory --- banking/banking/transaction_processing.py | 41 ----------------------- 1 file changed, 41 deletions(-) delete mode 100644 banking/banking/transaction_processing.py diff --git a/banking/banking/transaction_processing.py b/banking/banking/transaction_processing.py deleted file mode 100644 index 137cee646..000000000 --- a/banking/banking/transaction_processing.py +++ /dev/null @@ -1,41 +0,0 @@ -# banking/transaction_processing.py - -def deposit(account_id: int, amount: float) -> bool: - """ - Deposit an amount into an account. - - Args: - account_id (int): The ID of the account. - amount (float): The amount to deposit. - - Returns: - bool: True if the deposit was successful, False otherwise. - """ - # implementation - -def withdraw(account_id: int, amount: float) -> bool: - """ - Withdraw an amount from an account. - - Args: - account_id (int): The ID of the account. - amount (float): The amount to withdraw. - - Returns: -bool: True if the withdrawal was successful, False otherwise. - """ - # implementation - -def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool: - """ - Transfer an amount between two accounts. - - Args: - from_account_id (int): The ID of the source account. - to_account_id (int): The ID of the destination account. - amount (float): The amount to transfer. - - Returns: - bool: True if the transfer was successful, False otherwise. - """ - # implementation From f6675fdde3f68a17457d513d48899dbf6c480436 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:51:49 +0000 Subject: [PATCH 65/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 371383a according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- ai/ai.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ai/ai.py b/ai/ai.py index 338a2be76..86fd0f25b 100644 --- a/ai/ai.py +++ b/ai/ai.py @@ -2,8 +2,15 @@ import tensorflow as tf from tensorflow import keras + class AI: - def __init__(self, input_shape, output_shape, hidden_layers=None, activation_function=tf.nn.relu): + def __init__( + self, + input_shape, + output_shape, + hidden_layers=None, + activation_function=tf.nn.relu, + ): """ Initializes the AI class with the specified input and output shapes, and optional hidden layer sizes and activation function. """ @@ -23,7 +30,9 @@ def build_model(self): if self.hidden_layers is not None: for hidden_layer in self.hidden_layers: - x = keras.layers.Dense(hidden_layer, activation=self.activation_function)(x) + x = keras.layers.Dense( + hidden_layer, activation=self.activation_function + )(x) outputs = keras.layers.Dense(self.output_shape)(x) From 2c8c4b8cfa47480204d68e22d3522bd77d22610b Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:53:10 +0700 Subject: [PATCH 66/89] Create hardware.py --- hardware_integration/hardware.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 hardware_integration/hardware.py diff --git a/hardware_integration/hardware.py b/hardware_integration/hardware.py new file mode 100644 index 000000000..888d1c51a --- /dev/null +++ b/hardware_integration/hardware.py @@ -0,0 +1,29 @@ +import RPi.GPIO as GPIO + +def setup_i2c(sda_pin, scl_pin): + """ + Sets up the I2C communication protocol using the specified SDA and SCL pins. + """ + GPIO.setmode(GPIO.BCM) + GPIO.setup(sda_pin, GPIO.OUT) + GPIO.setup(scl_pin, GPIO.OUT) + GPIO.output(sda_pin, GPIO.HIGH) + GPIO.output(scl_pin, GPIO.HIGH) + GPIO.setmode(GPIO.BCM) + GPIO.setup(sda_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.setup(scl_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +def setup_spi(sclk_pin, mosi_pin, miso_pin): + """ + Sets up the SPI communication protocol using the specified SCLK, MOSI, and MISO pins. + """ + GPIO.setmode(GPIO.BCM) + GPIO.setup(sclk_pin, GPIO.OUT) + GPIO.setup(mosi_pin, GPIO.OUT) + GPIO.setup(miso_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +def cleanup(): + """ + Cleans up the GPIO pins and resets the GPIO library. + """ + GPIO.cleanup() From 95af09132e43456cb73ad8d8168bdd97a20ca81a Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:53:30 +0000 Subject: [PATCH 67/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 2c8c4b8 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- hardware_integration/hardware.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware_integration/hardware.py b/hardware_integration/hardware.py index 888d1c51a..ac236d2fa 100644 --- a/hardware_integration/hardware.py +++ b/hardware_integration/hardware.py @@ -1,5 +1,6 @@ import RPi.GPIO as GPIO + def setup_i2c(sda_pin, scl_pin): """ Sets up the I2C communication protocol using the specified SDA and SCL pins. @@ -13,6 +14,7 @@ def setup_i2c(sda_pin, scl_pin): GPIO.setup(sda_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(scl_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + def setup_spi(sclk_pin, mosi_pin, miso_pin): """ Sets up the SPI communication protocol using the specified SCLK, MOSI, and MISO pins. @@ -22,6 +24,7 @@ def setup_spi(sclk_pin, mosi_pin, miso_pin): GPIO.setup(mosi_pin, GPIO.OUT) GPIO.setup(miso_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + def cleanup(): """ Cleans up the GPIO pins and resets the GPIO library. From de250eaac60153d06948d71252e053a1270967ca Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:53:46 +0700 Subject: [PATCH 68/89] Create sensor.py --- hardware_integration/sensor.py | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 hardware_integration/sensor.py diff --git a/hardware_integration/sensor.py b/hardware_integration/sensor.py new file mode 100644 index 000000000..b6b37c29e --- /dev/null +++ b/hardware_integration/sensor.py @@ -0,0 +1,49 @@ +import hardware + +def read_temperature_sensor(i2c_address): + """ + Reads the temperature from the specified I2C temperature sensor. + """ + # Set up I2C communication + sda_pin = 2 + scl_pin = 3 + hardware.setup_i2c(sda_pin, scl_pin) + + # Read temperature sensor data + temperature_data = [0x00, 0x00] + for i in range(2): + hardware.write_i2c_data(i2c_address, [0x00], 1) + temperature_data[i] = hardware.read_i2c_data(i2c_address, 1)[0] + + # Convert temperature data to temperature value + temperature = (temperature_data[0] << 8) | temperature_data[1] + temperature = temperature / 16.0 + + # Clean up I2C communication + hardware.cleanup() + + return temperature + +def read_humidity_sensor(i2c_address): + """ + Reads the humidity from the specified I2C humidity sensor. + """ + # Set up I2C communication + sda_pin = 2 + scl_pin = 3 + hardware.setup_i2c(sda_pin, scl_pin) + + # Read humidity sensor data + humidity_data = [0x00, 0x00] + for i in range(2): + hardware.write_i2c_data(i2c_address, [0x00], 1) + humidity_data[i] = hardware.read_i2c_data(i2c_address, 1)[0] + + # Convert humidity data to humidity value + humidity = (humidity_data[0] << 8) | humidity_data[1] + humidity = humidity / 16.0 + + # Clean up I2C communication + hardware.cleanup() + + return humidity From 3a39f5e3de47248ac3a73dd28b91aee0463b22a5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:54:12 +0000 Subject: [PATCH 69/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in de250ea according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- hardware_integration/sensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware_integration/sensor.py b/hardware_integration/sensor.py index b6b37c29e..d65205514 100644 --- a/hardware_integration/sensor.py +++ b/hardware_integration/sensor.py @@ -1,5 +1,6 @@ import hardware + def read_temperature_sensor(i2c_address): """ Reads the temperature from the specified I2C temperature sensor. @@ -24,6 +25,7 @@ def read_temperature_sensor(i2c_address): return temperature + def read_humidity_sensor(i2c_address): """ Reads the humidity from the specified I2C humidity sensor. From 8affc5994e6060ee08a789f8a498b8e44bdaa314 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:56:01 +0700 Subject: [PATCH 70/89] Create accounts.py --- banking/accounts.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 banking/accounts.py diff --git a/banking/accounts.py b/banking/accounts.py new file mode 100644 index 000000000..71a3a9781 --- /dev/null +++ b/banking/accounts.py @@ -0,0 +1,34 @@ +class BankAccount: + """ + Represents a bank account with a balance and transaction history. + """ + def __init__(self, account_number, balance=0): + """ + Initializes a new bank account with the specified account number and balance. + """ + self.account_number = account_number + self.balance = balance + self.transaction_history = [] + + def deposit(self, amount): + """ + Deposits the specified amount into the bank account. + """ + self.balance += amount + self.transaction_history.append(f"Deposit: ${amount:.2f}") + + def withdraw(self, amount): + """ + Withdraws the specified amount from the bank account, if sufficient funds are available. + """ + if self.balance >= amount: + self.balance -= amount + self.transaction_history.append(f"Withdraw: ${amount:.2f}") + else: + raise InsufficientFundsError(f"Insufficient funds to withdraw ${amount:.2f} from account {self.account_number}") + +class InsufficientFundsError(Exception): + """ + Raised when there are insufficient funds to complete a withdrawal. + """ + pass From a5e9a381804a8438a46bf80e35bdfdb3cb265faa Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:56:21 +0000 Subject: [PATCH 71/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 8affc59 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- banking/accounts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/banking/accounts.py b/banking/accounts.py index 71a3a9781..a40c1143d 100644 --- a/banking/accounts.py +++ b/banking/accounts.py @@ -2,6 +2,7 @@ class BankAccount: """ Represents a bank account with a balance and transaction history. """ + def __init__(self, account_number, balance=0): """ Initializes a new bank account with the specified account number and balance. @@ -25,10 +26,14 @@ def withdraw(self, amount): self.balance -= amount self.transaction_history.append(f"Withdraw: ${amount:.2f}") else: - raise InsufficientFundsError(f"Insufficient funds to withdraw ${amount:.2f} from account {self.account_number}") + raise InsufficientFundsError( + f"Insufficient funds to withdraw ${amount:.2f} from account {self.account_number}" + ) + class InsufficientFundsError(Exception): """ Raised when there are insufficient funds to complete a withdrawal. """ + pass From 3ea2281a5222d496c81ff08f81bcc94aff232d9c Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:56:40 +0700 Subject: [PATCH 72/89] Create transaction.py --- banking/transaction.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 banking/transaction.py diff --git a/banking/transaction.py b/banking/transaction.py new file mode 100644 index 000000000..9c6217151 --- /dev/null +++ b/banking/transaction.py @@ -0,0 +1,16 @@ +from datetime import datetime +from banking.accounts import BankAccount + +def transfer(from_account: BankAccount, to_account: BankAccount, amount): + """ + Transfers the specified amount from the from_account to the to_account. + """ + from_account.withdraw(amount) + to_account.deposit(amount) + + transaction_date = datetime.now() + from_account_number = from_account.account_number + to_account_number = to_account.account_number + transaction_amount = amount + + print(f"Transfer from account {from_account_number} to account {to_account_number} for ${transaction_amount:.2f} on {transaction_date}") From d9289f61c5fd01b1d56483eecffbdcabf4156d97 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:57:03 +0000 Subject: [PATCH 73/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 3ea2281 according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- banking/transaction.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/banking/transaction.py b/banking/transaction.py index 9c6217151..970465667 100644 --- a/banking/transaction.py +++ b/banking/transaction.py @@ -1,6 +1,8 @@ from datetime import datetime + from banking.accounts import BankAccount + def transfer(from_account: BankAccount, to_account: BankAccount, amount): """ Transfers the specified amount from the from_account to the to_account. @@ -13,4 +15,6 @@ def transfer(from_account: BankAccount, to_account: BankAccount, amount): to_account_number = to_account.account_number transaction_amount = amount - print(f"Transfer from account {from_account_number} to account {to_account_number} for ${transaction_amount:.2f} on {transaction_date}") + print( + f"Transfer from account {from_account_number} to account {to_account_number} for ${transaction_amount:.2f} on {transaction_date}" + ) From f62245dbf149343f112f484c50f06ecb92b3175e Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 21:59:14 +0700 Subject: [PATCH 74/89] Create bank.py --- banking/bank.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 banking/bank.py diff --git a/banking/bank.py b/banking/bank.py new file mode 100644 index 000000000..7123803b8 --- /dev/null +++ b/banking/bank.py @@ -0,0 +1,43 @@ +from banking.accounts import BankAccount +from banking.transactions import transfer + +def create_account(account_number): + """ + Creates a new bank account with the specified account number. + """ + return BankAccount(account_number) + +def get_account(account_number): + """ +Retrieves the bank account with the specified account number. + """ + # Load account data from database or other storage system + account_data = load_account_data(account_number) + + # Create new account if it doesn't exist + if account_data is None: + account = create_account(account_number) + else: + account = BankAccount(account_number, balance=account_data["balance"]) + + return account + +def save_account(account): + """ + Saves the specified bank account to the database or other storage system. + """ + # Save account data to database or other storage system + save_account_data(account.account_number, account.balance) + +def process_transaction(transaction): + """ + Processes the specified transaction by transferring funds between bank accounts. + """ + from_account = get_account(transaction["from_account"]) + to_account = get_account(transaction["to_account"]) + amount = transaction["amount"] + + transfer(from_account, to_account, amount) + + save_account(from_account) + save_account(to_account) From 1910d9952df552643334342906d511457bbb59e6 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 14:59:36 +0000 Subject: [PATCH 75/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in f62245d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- banking/bank.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/banking/bank.py b/banking/bank.py index 7123803b8..dab15c962 100644 --- a/banking/bank.py +++ b/banking/bank.py @@ -1,15 +1,17 @@ from banking.accounts import BankAccount from banking.transactions import transfer + def create_account(account_number): """ Creates a new bank account with the specified account number. """ return BankAccount(account_number) + def get_account(account_number): """ -Retrieves the bank account with the specified account number. + Retrieves the bank account with the specified account number. """ # Load account data from database or other storage system account_data = load_account_data(account_number) @@ -22,6 +24,7 @@ def get_account(account_number): return account + def save_account(account): """ Saves the specified bank account to the database or other storage system. @@ -29,6 +32,7 @@ def save_account(account): # Save account data to database or other storage system save_account_data(account.account_number, account.balance) + def process_transaction(transaction): """ Processes the specified transaction by transferring funds between bank accounts. From 709cd5d3a41f1ee152df2d3c4f1ea773775e7875 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:02:01 +0700 Subject: [PATCH 76/89] Update bank.py --- banking/bank.py | 59 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/banking/bank.py b/banking/bank.py index 7123803b8..f60deb6f8 100644 --- a/banking/bank.py +++ b/banking/bank.py @@ -1,24 +1,33 @@ -from banking.accounts import BankAccount -from banking.transactions import transfer +from banking.accounts import BankAccount, SavingsAccount, CheckingAccount, InsufficientFundsError +from banking.transactions import transfer, pay_bill -def create_account(account_number): +def create_account(account_type, account_number): """ - Creates a new bank account with the specified account number. + Creates a new bank account with the specified account type and account number. """ - return BankAccount(account_number) + if account_type == "savings": + account = SavingsAccount(account_number) + elif account_type == "checking": + account = CheckingAccount(account_number) + else: + raise ValueError(f"Invalid account type: {account_type}") + + return account def get_account(account_number): """ -Retrieves the bank account with the specified account number. + Retrieves the bank account with the specified account number. """ # Load account data from database or other storage system account_data = load_account_data(account_number) # Create new account if it doesn't exist if account_data is None: - account = create_account(account_number) + account_type = None else: - account = BankAccount(account_number, balance=account_data["balance"]) + account_type = account_data["type"] + + account = create_account(account_type, account_number) return account @@ -27,17 +36,35 @@ def save_account(account): Saves the specified bank account to the database or other storage system. """ # Save account data to database or other storage system - save_account_data(account.account_number, account.balance) + save_account_data(account.account_number, account.type, account.balance) def process_transaction(transaction): """ - Processes the specified transaction by transferring funds between bank accounts. + Processes the specified transaction by transferring funds between bank accounts or paying a bill. """ - from_account = get_account(transaction["from_account"]) - to_account = get_account(transaction["to_account"]) - amount = transaction["amount"] + transaction_type = transaction["type"] + + if transaction_type == "transfer": + from_account_number = transaction["from_account"] + to_account_number = transaction["to_account"] + amount = transaction["amount"] + + from_account = get_account(from_account_number) + to_account = get_account(to_account_number) + + transfer(from_account, to_account, amount) + + save_account(from_account) + save_account(to_account) + + elif transaction_type == "pay_bill": + account_number = transaction["account"] + payee = transaction["payee"] + amount = transaction["amount"] + due_date = transaction["due_date"] + + account = get_account(account_number) - transfer(from_account, to_account, amount) + pay_bill(account, payee, amount, due_date) - save_account(from_account) - save_account(to_account) + save_account(account) From d65299243edd2a37ee3ff8ca1e6c9824cc4aff54 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 15:02:21 +0000 Subject: [PATCH 77/89] style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf This commit fixes the style issues introduced in 709cd5d according to the output from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf. Details: None --- banking/bank.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/banking/bank.py b/banking/bank.py index f60deb6f8..aad97015f 100644 --- a/banking/bank.py +++ b/banking/bank.py @@ -1,5 +1,11 @@ -from banking.accounts import BankAccount, SavingsAccount, CheckingAccount, InsufficientFundsError -from banking.transactions import transfer, pay_bill +from banking.accounts import ( + BankAccount, + CheckingAccount, + InsufficientFundsError, + SavingsAccount, +) +from banking.transactions import pay_bill, transfer + def create_account(account_type, account_number): """ @@ -14,6 +20,7 @@ def create_account(account_type, account_number): return account + def get_account(account_number): """ Retrieves the bank account with the specified account number. @@ -31,6 +38,7 @@ def get_account(account_number): return account + def save_account(account): """ Saves the specified bank account to the database or other storage system. @@ -38,6 +46,7 @@ def save_account(account): # Save account data to database or other storage system save_account_data(account.account_number, account.type, account.balance) + def process_transaction(transaction): """ Processes the specified transaction by transferring funds between bank accounts or paying a bill. From 9d01cd8c7d466436a10ea4f5a46e51fe8478af71 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:17:52 +0700 Subject: [PATCH 78/89] Create node.js.yml --- .github/workflows/node.js.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 000000000..6d573d77d --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm test From d4d7f1f3be260336bdeb5735909cdcaa93bbc68b Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:18:25 +0700 Subject: [PATCH 79/89] Create webpack.yml --- .github/workflows/webpack.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/webpack.yml diff --git a/.github/workflows/webpack.yml b/.github/workflows/webpack.yml new file mode 100644 index 000000000..25e64c08e --- /dev/null +++ b/.github/workflows/webpack.yml @@ -0,0 +1,28 @@ +name: NodeJS with Webpack + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Build + run: | + npm install + npx webpack From f11ed59657a827f2703305dbfe919f1815ba8fc5 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:19:07 +0700 Subject: [PATCH 80/89] Create ruby.yml --- .github/workflows/ruby.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 000000000..5d80832d3 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,38 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: Ruby + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + test: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.6', '2.7', '3.0'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake From d0119f2e9f9ebda487748951e2cbea8d1d8645d3 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:19:55 +0700 Subject: [PATCH 81/89] Create symfony.yml --- .github/workflows/symfony.yml | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/symfony.yml diff --git a/.github/workflows/symfony.yml b/.github/workflows/symfony.yml new file mode 100644 index 000000000..e9b7c26f6 --- /dev/null +++ b/.github/workflows/symfony.yml @@ -0,0 +1,47 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Symfony + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + symfony-tests: + runs-on: ubuntu-latest + steps: + # To automatically get bug fixes and new Php versions for shivammathur/setup-php, + # change this to (see https://github.com/shivammathur/setup-php#bookmark-versioning): + # uses: shivammathur/setup-php@v2 + - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28 + with: + php-version: '8.0' + - uses: actions/checkout@v4 + - name: Copy .env.test.local + run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');" + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: Create Database + run: | + mkdir -p data + touch data/database.sqlite + - name: Execute tests (Unit and Feature tests) via PHPUnit + env: + DATABASE_URL: sqlite:///%kernel.project_dir%/data/database.sqlite + run: vendor/bin/phpunit From c18293e6c63cd553ea37d7a9812467d57c081511 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:20:44 +0700 Subject: [PATCH 82/89] Create dart.yml --- .github/workflows/dart.yml | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/dart.yml diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml new file mode 100644 index 000000000..3383c717e --- /dev/null +++ b/.github/workflows/dart.yml @@ -0,0 +1,42 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Dart + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + # Note: This workflow uses the latest stable version of the Dart SDK. + # You can specify other versions if desired, see documentation here: + # https://github.com/dart-lang/setup-dart/blob/main/README.md + # - uses: dart-lang/setup-dart@v1 + - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603 + + - name: Install dependencies + run: dart pub get + + # Uncomment this step to verify the use of 'dart format' on each commit. + # - name: Verify formatting + # run: dart format --output=none --set-exit-if-changed . + + # Consider passing '--fatal-infos' for slightly stricter analysis. + - name: Analyze project source + run: dart analyze + + # Your project will need to have tests in test/ and a dependency on + # package:test for this step to succeed. Note that Flutter projects will + # want to change this to 'flutter test'. + - name: Run tests + run: dart test From 2bbabd0af6f04ee2ba4923b902c3cd4b23e5246a Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:21:35 +0700 Subject: [PATCH 83/89] Create dotnet.yml --- .github/workflows/dotnet.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 000000000..217f7cbec --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,28 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From 9aa1802e3f93e3c899ae7c1b67fc5dac79c6f55c Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:22:11 +0700 Subject: [PATCH 84/89] Create laravel.yml --- .github/workflows/laravel.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/laravel.yml diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml new file mode 100644 index 000000000..fd8c644e6 --- /dev/null +++ b/.github/workflows/laravel.yml @@ -0,0 +1,35 @@ +name: Laravel + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + laravel-tests: + + runs-on: ubuntu-latest + + steps: + - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + with: + php-version: '8.0' + - uses: actions/checkout@v4 + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Create Database + run: | + mkdir -p database + touch database/database.sqlite + - name: Execute tests (Unit and Feature tests) via PHPUnit/Pest + env: + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite + run: php artisan test From 16d3d3297feeb515e3f29740915f57127fddff35 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:22:49 +0700 Subject: [PATCH 85/89] Create go.yml --- .github/workflows/go.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 000000000..0b443f376 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,28 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From 5b5865f81f0fdc89eb56b545bb94630d66702417 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:23:39 +0700 Subject: [PATCH 86/89] Create r.yml --- .github/workflows/r.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/r.yml diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml new file mode 100644 index 000000000..ed8aacfa6 --- /dev/null +++ b/.github/workflows/r.yml @@ -0,0 +1,40 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# +# See https://github.com/r-lib/actions/tree/master/examples#readme for +# additional example workflows available for the R community. + +name: R + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + runs-on: macos-latest + strategy: + matrix: + r-version: ['3.6.3', '4.1.1'] + + steps: + - uses: actions/checkout@v4 + - name: Set up R ${{ matrix.r-version }} + uses: r-lib/actions/setup-r@f57f1301a053485946083d7a45022b278929a78a + with: + r-version: ${{ matrix.r-version }} + - name: Install dependencies + run: | + install.packages(c("remotes", "rcmdcheck")) + remotes::install_deps(dependencies = TRUE) + shell: Rscript {0} + - name: Check + run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") + shell: Rscript {0} From 50d818e8eedcd3416d374b23e1b0127f48a2dc98 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:24:25 +0700 Subject: [PATCH 87/89] Create gradle.yml --- .github/workflows/gradle.yml | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 000000000..27400c2ba --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,67 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew build + + # NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html). + # If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version. + # + # - name: Setup Gradle + # uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + # with: + # gradle-version: '8.5' + # + # - name: Build with Gradle 8.5 + # run: gradle build + + dependency-submission: + + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. + # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 From 7962d1d436038a4c59116bd1d4b5b1571eb321b7 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 22:27:34 +0700 Subject: [PATCH 88/89] Create terraform.yml --- .github/workflows/terraform.yml | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/terraform.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 000000000..540e8040b --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,93 @@ +# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file +# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run +# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events +# to the "main" branch, `terraform apply` will be executed. +# +# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform +# +# To use this workflow, you will need to complete the following setup steps. +# +# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined. +# Example `main.tf`: +# # The configuration for the `remote` backend. +# terraform { +# backend "remote" { +# # The name of your Terraform Cloud organization. +# organization = "example-organization" +# +# # The name of the Terraform Cloud workspace to store Terraform state files in. +# workspaces { +# name = "example-workspace" +# } +# } +# } +# +# # An example resource that does nothing. +# resource "null_resource" "example" { +# triggers = { +# value = "A example resource that does nothing!" +# } +# } +# +# +# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository. +# Documentation: +# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html +# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets +# +# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action. +# Example: +# - name: Setup Terraform +# uses: hashicorp/setup-terraform@v1 +# with: +# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + +name: 'Terraform' + +on: + push: + branches: [ "main" ] + pull_request: + +permissions: + contents: read + +jobs: + terraform: + name: 'Terraform' + runs-on: ubuntu-latest + environment: production + + # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest + defaults: + run: + shell: bash + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v4 + + # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token + - name: Setup Terraform + uses: hashicorp/setup-terraform@v1 + with: + cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + run: terraform init + + # Checks that all Terraform configuration files adhere to a canonical format + - name: Terraform Format + run: terraform fmt -check + + # Generates an execution plan for Terraform + - name: Terraform Plan + run: terraform plan -input=false + + # On push to "main", build or change infrastructure according to Terraform configuration files + # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks + - name: Terraform Apply + if: github.ref == 'refs/heads/"main"' && github.event_name == 'push' + run: terraform apply -auto-approve -input=false From 9ce2191ee8464ea65e5a9e9c632e51da0c7f60c2 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Fri, 10 May 2024 23:55:01 +0700 Subject: [PATCH 89/89] Update transaction_processing.py --- banking/transaction_processing.py | 82 ++++++++++++++----------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/banking/transaction_processing.py b/banking/transaction_processing.py index bc86a6e49..21924650b 100644 --- a/banking/transaction_processing.py +++ b/banking/transaction_processing.py @@ -13,23 +13,17 @@ def deposit(account_id: int, amount: float) -> bool: Returns: bool: True if the deposit was successful, False otherwise. """ - # implementation - logging.info(f"Depositing {amount} into account {account_id}") - # Retrieve the account from the database or in-memory data structure - account = get_account_by_id(account_id) - - # Validate the input parameters - if amount < 0: - raise ValueError("Amount cannot be negative") - - # Update the account balance - account['balance'] += amount - - # Save the updated account back to the database or in-memory data structure - save_account(account) - - # Return True to indicate success - return True + try: + logging.info(f"Depositing {amount} into account {account_id}") + account = get_account_by_id(account_id) + if amount < 0: + raise ValueError("Amount cannot be negative") + account['balance'] += amount + save_account(account) + return True + except Exception as e: + logging.error(f"Error depositing into account {account_id}: {e}") + return False def withdraw(account_id: int, amount: float) -> bool: """ @@ -42,25 +36,19 @@ def withdraw(account_id: int, amount: float) -> bool: Returns: bool: True if the withdrawal was successful, False otherwise. """ - # implementation - logging.info(f"Withdrawing {amount} from account {account_id}") - # Retrieve the account from the database or in-memory data structure - account = get_account_by_id(account_id) - - # Validate the input parameters - if amount < 0: - raise ValueError("Amount cannot be negative") - if account['balance'] < amount: - raise ValueError("Insufficient balance") - - # Update the account balance - account['balance'] -= amount - - # Save the updated account back to the database or in-memory data structure - save_account(account) - - # Return True to indicate success - return True + try: + logging.info(f"Withdrawing {amount} from account {account_id}") + account = get_account_by_id(account_id) + if amount < 0: + raise ValueError("Amount cannot be negative") + if account['balance'] < amount: + raise ValueError("Insufficient balance") + account['balance'] -= amount + save_account(account) + return True + except Exception as e: + logging.error(f"Error withdrawing from account {account_id}: {e}") + return False def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool: """ @@ -74,13 +62,15 @@ def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool: Returns: bool: True if the transfer was successful, False otherwise. """ - # implementation - logging.info(f"Transferring {amount} from account {from_account_id} to account {to_account_id}") - # Withdraw the amount from the source account - withdraw(from_account_id, amount) - - # Deposit the amount into the destination account - deposit(to_account_id, amount) - - # Return True to indicate success - return True + try: + logging.info(f"Transferring {amount} from account {from_account_id} to account {to_account_id}") + if not withdraw(from_account_id, amount): + return False + if not deposit(to_account_id, amount): + # Rollback the withdrawal if deposit fails + deposit(from_account_id, amount) + return False + return True + except Exception as e: + logging.error(f"Error transferring between accounts: {e}") + return False