greenmining 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,802 @@
1
+ """
2
+ Green Software Foundation Patterns
3
+ Official patterns from https://patterns.greensoftware.foundation/
4
+
5
+ Categories: Cloud (40+ patterns), Web (15+ patterns), AI/ML (10+ patterns)
6
+ Total: 65+ official GSF patterns
7
+ """
8
+
9
+ GSF_PATTERNS = {
10
+ # ==================== CLOUD PATTERNS (40+) ====================
11
+ "cache_static_data": {
12
+ "name": "Cache Static Data",
13
+ "category": "cloud",
14
+ "keywords": ["cache", "caching", "static", "cdn", "redis", "memcache", "cached"],
15
+ "description": "Cache static content to reduce server load and network transfers",
16
+ "sci_impact": "Reduces energy by minimizing redundant compute and network operations",
17
+ },
18
+ "choose_region_closest": {
19
+ "name": "Choose Region Closest to Users",
20
+ "category": "cloud",
21
+ "keywords": ["region", "closest", "proximity", "latency", "location", "geographic"],
22
+ "description": "Deploy in regions closest to users to reduce network distance",
23
+ "sci_impact": "Less energy for network transmission, lower latency",
24
+ },
25
+ "compress_stored_data": {
26
+ "name": "Compress Stored Data",
27
+ "category": "cloud",
28
+ "keywords": ["compress", "compression", "stored", "storage", "gzip", "zstd"],
29
+ "description": "Compress data at rest to reduce storage footprint",
30
+ "sci_impact": "Lower embodied carbon from reduced storage infrastructure",
31
+ },
32
+ "compress_transmitted_data": {
33
+ "name": "Compress Transmitted Data",
34
+ "category": "cloud",
35
+ "keywords": ["compress", "transmission", "gzip", "brotli", "network"],
36
+ "description": "Compress data before transmission over network",
37
+ "sci_impact": "Reduces network energy consumption and transfer time",
38
+ },
39
+ "containerize_workload": {
40
+ "name": "Containerize Your Workload",
41
+ "category": "cloud",
42
+ "keywords": ["container", "docker", "kubernetes", "containerize", "pod"],
43
+ "description": "Use containers for better resource utilization",
44
+ "sci_impact": "Improved resource density and efficiency",
45
+ },
46
+ "delete_unused_storage": {
47
+ "name": "Delete Unused Storage Resources",
48
+ "category": "cloud",
49
+ "keywords": ["delete", "remove", "unused", "storage", "cleanup", "orphan"],
50
+ "description": "Remove storage resources that are no longer needed",
51
+ "sci_impact": "Eliminates wasted energy and embodied carbon",
52
+ },
53
+ "encrypt_necessary": {
54
+ "name": "Encrypt What Is Necessary",
55
+ "category": "cloud",
56
+ "keywords": ["encrypt", "encryption", "tls", "ssl", "crypto"],
57
+ "description": "Only encrypt data that requires protection",
58
+ "sci_impact": "Reduces CPU overhead from unnecessary encryption",
59
+ },
60
+ "evaluate_cpu_architectures": {
61
+ "name": "Evaluate Other CPU Architectures",
62
+ "category": "cloud",
63
+ "keywords": ["cpu", "architecture", "arm", "graviton", "processor"],
64
+ "description": "Consider ARM and other efficient CPU architectures",
65
+ "sci_impact": "Some architectures offer better energy efficiency",
66
+ },
67
+ "service_mesh": {
68
+ "name": "Evaluate Using a Service Mesh",
69
+ "category": "cloud",
70
+ "keywords": ["service mesh", "istio", "linkerd", "envoy"],
71
+ "description": "Use service mesh for efficient service-to-service communication",
72
+ "sci_impact": "Optimizes network traffic and observability overhead",
73
+ },
74
+ "tls_termination": {
75
+ "name": "Evaluate TLS Termination",
76
+ "category": "cloud",
77
+ "keywords": ["tls", "termination", "ssl", "offload"],
78
+ "description": "Terminate TLS at edge to reduce encryption overhead",
79
+ "sci_impact": "Reduces CPU load on backend services",
80
+ },
81
+ "stateless_design": {
82
+ "name": "Implement Stateless Design",
83
+ "category": "cloud",
84
+ "keywords": ["stateless", "state", "session", "horizontal"],
85
+ "description": "Design services without server-side state",
86
+ "sci_impact": "Enables better scaling and resource utilization",
87
+ },
88
+ "match_slo": {
89
+ "name": "Match SLO Requirements",
90
+ "category": "cloud",
91
+ "keywords": ["slo", "sla", "service level", "objective"],
92
+ "description": "Don't over-engineer beyond required SLO",
93
+ "sci_impact": "Avoids wasted resources on unnecessary performance",
94
+ },
95
+ "match_vm_utilization": {
96
+ "name": "Match VM Utilization Requirements",
97
+ "category": "cloud",
98
+ "keywords": ["vm", "virtual machine", "instance", "size", "utilization"],
99
+ "description": "Right-size VMs to actual workload needs",
100
+ "sci_impact": "Eliminates idle resources and wasted energy",
101
+ },
102
+ "minimize_environments": {
103
+ "name": "Minimize Deployed Environments",
104
+ "category": "cloud",
105
+ "keywords": ["environment", "dev", "staging", "ephemeral"],
106
+ "description": "Reduce number of permanent test/dev environments",
107
+ "sci_impact": "Less idle infrastructure consuming energy",
108
+ },
109
+ "optimize_storage_utilization": {
110
+ "name": "Optimize Storage Resource Utilization",
111
+ "category": "cloud",
112
+ "keywords": ["storage", "optimize", "utilization", "efficiency"],
113
+ "description": "Maximize usage of provisioned storage",
114
+ "sci_impact": "Better hardware efficiency, less waste",
115
+ },
116
+ "optimize_avg_cpu": {
117
+ "name": "Optimize Average CPU Utilization",
118
+ "category": "cloud",
119
+ "keywords": ["cpu", "utilization", "average", "optimize"],
120
+ "description": "Increase average CPU utilization across fleet",
121
+ "sci_impact": "More work per unit of energy consumed",
122
+ },
123
+ "optimize_peak_cpu": {
124
+ "name": "Optimize Peak CPU Utilization",
125
+ "category": "cloud",
126
+ "keywords": ["cpu", "peak", "spike", "burst"],
127
+ "description": "Handle peaks efficiently without over-provisioning",
128
+ "sci_impact": "Reduces need for excess capacity",
129
+ },
130
+ "queue_non_urgent": {
131
+ "name": "Queue Non-Urgent Requests",
132
+ "category": "cloud",
133
+ "keywords": ["queue", "async", "batch", "defer", "background"],
134
+ "description": "Queue non-urgent work for batch processing",
135
+ "sci_impact": "Better resource utilization and scheduling",
136
+ },
137
+ "reduce_network_traversal": {
138
+ "name": "Reduce Network Traversal Between VMs",
139
+ "category": "cloud",
140
+ "keywords": ["network", "traversal", "hop", "latency", "cross-az"],
141
+ "description": "Minimize network hops between services",
142
+ "sci_impact": "Less network equipment and energy per request",
143
+ },
144
+ "reduce_transmitted_data": {
145
+ "name": "Reduce Transmitted Data",
146
+ "category": "cloud",
147
+ "keywords": ["reduce", "data", "transmission", "payload", "bandwidth"],
148
+ "description": "Send only necessary data over network",
149
+ "sci_impact": "Lower network energy consumption",
150
+ },
151
+ "remove_unused_assets": {
152
+ "name": "Remove Unused Assets",
153
+ "category": "cloud",
154
+ "keywords": ["remove", "unused", "asset", "cleanup", "garbage"],
155
+ "description": "Delete unused code, images, dependencies",
156
+ "sci_impact": "Reduces storage and deployment footprint",
157
+ },
158
+ "scale_down_k8s": {
159
+ "name": "Scale Down Kubernetes Workloads",
160
+ "category": "cloud",
161
+ "keywords": ["scale down", "kubernetes", "k8s", "downscale", "hpa"],
162
+ "description": "Automatically scale down idle K8s workloads",
163
+ "sci_impact": "Eliminates idle resource consumption",
164
+ },
165
+ "scale_down_apps": {
166
+ "name": "Scale Down Unused Applications",
167
+ "category": "cloud",
168
+ "keywords": ["scale", "down", "idle", "suspend", "hibernate"],
169
+ "description": "Scale down or shut down idle applications",
170
+ "sci_impact": "Reduces energy from idle services",
171
+ },
172
+ "scale_with_load": {
173
+ "name": "Scale Infrastructure with User Load",
174
+ "category": "cloud",
175
+ "keywords": ["autoscale", "scale", "elastic", "demand", "load"],
176
+ "description": "Automatically scale based on actual demand",
177
+ "sci_impact": "Matches resources to need, eliminates waste",
178
+ },
179
+ "k8s_event_scaling": {
180
+ "name": "Scale Kubernetes Workloads Based on Events",
181
+ "category": "cloud",
182
+ "keywords": ["keda", "event", "scale", "kubernetes", "queue"],
183
+ "description": "Scale based on queue depth or event metrics",
184
+ "sci_impact": "Precise scaling to actual workload",
185
+ },
186
+ "scale_logical_components": {
187
+ "name": "Scale Logical Components Independently",
188
+ "category": "cloud",
189
+ "keywords": ["microservice", "component", "independent", "decouple"],
190
+ "description": "Scale services independently based on their load",
191
+ "sci_impact": "Avoids scaling entire application for one bottleneck",
192
+ },
193
+ "scan_vulnerabilities": {
194
+ "name": "Scan for Vulnerabilities",
195
+ "category": "cloud",
196
+ "keywords": ["security", "vulnerability", "scan", "cve"],
197
+ "description": "Regular security scans to prevent breaches",
198
+ "sci_impact": "Prevents energy waste from attacks and remediation",
199
+ },
200
+ "retention_policy": {
201
+ "name": "Set Retention Policy on Storage",
202
+ "category": "cloud",
203
+ "keywords": ["retention", "policy", "lifecycle", "expire", "ttl"],
204
+ "description": "Automatically delete old data per policy",
205
+ "sci_impact": "Reduces storage footprint over time",
206
+ },
207
+ "shed_lower_priority": {
208
+ "name": "Shed Lower Priority Traffic",
209
+ "category": "cloud",
210
+ "keywords": ["shed", "priority", "throttle", "rate limit", "backpressure"],
211
+ "description": "Drop low-priority requests under load",
212
+ "sci_impact": "Protects resources for important work",
213
+ },
214
+ "time_shift_cron": {
215
+ "name": "Time-Shift Kubernetes Cron Jobs",
216
+ "category": "cloud",
217
+ "keywords": ["time shift", "cron", "schedule", "carbon aware", "renewable"],
218
+ "description": "Run batch jobs when renewable energy is available",
219
+ "sci_impact": "Uses cleaner energy sources",
220
+ },
221
+ "async_not_sync": {
222
+ "name": "Use Async Instead of Sync",
223
+ "category": "cloud",
224
+ "keywords": ["async", "asynchronous", "non-blocking", "await"],
225
+ "description": "Use asynchronous processing patterns",
226
+ "sci_impact": "Better CPU utilization, less idle time",
227
+ },
228
+ "circuit_breaker": {
229
+ "name": "Use Circuit Breaker",
230
+ "category": "cloud",
231
+ "keywords": ["circuit breaker", "fault tolerance", "resilience", "fallback"],
232
+ "description": "Prevent cascading failures with circuit breakers",
233
+ "sci_impact": "Avoids wasted energy on failing requests",
234
+ },
235
+ "cloud_native_security": {
236
+ "name": "Use Cloud Native Security Tools",
237
+ "category": "cloud",
238
+ "keywords": ["security", "native", "managed", "cloud"],
239
+ "description": "Use cloud provider's native security services",
240
+ "sci_impact": "More efficient than running own security infrastructure",
241
+ },
242
+ "compiled_languages": {
243
+ "name": "Use Compiled Languages",
244
+ "category": "cloud",
245
+ "keywords": ["compile", "compiled", "rust", "go", "c++"],
246
+ "description": "Consider compiled languages for CPU-intensive tasks",
247
+ "sci_impact": "Better runtime performance and energy efficiency",
248
+ },
249
+ "ddos_protection": {
250
+ "name": "Use DDoS Protection",
251
+ "category": "cloud",
252
+ "keywords": ["ddos", "protection", "shield", "waf"],
253
+ "description": "Protect against distributed denial of service",
254
+ "sci_impact": "Prevents energy waste from malicious traffic",
255
+ },
256
+ "energy_efficient_hardware": {
257
+ "name": "Use Energy Efficient Hardware",
258
+ "category": "cloud",
259
+ "keywords": ["energy", "efficient", "hardware", "green", "sustainable"],
260
+ "description": "Choose hardware optimized for energy efficiency",
261
+ "sci_impact": "Direct reduction in energy consumption",
262
+ },
263
+ # ==================== WEB PATTERNS (15+) ====================
264
+ "avoid_chaining_requests": {
265
+ "name": "Avoid Chaining Critical Requests",
266
+ "category": "web",
267
+ "keywords": ["chain", "critical", "request", "waterfall", "sequential"],
268
+ "description": "Avoid serialized network requests that block rendering",
269
+ "sci_impact": "Faster page load, less energy for rendering",
270
+ },
271
+ "avoid_excessive_dom": {
272
+ "name": "Avoid Excessive DOM Size",
273
+ "category": "web",
274
+ "keywords": ["dom", "size", "excessive", "tree", "nodes"],
275
+ "description": "Keep DOM tree small and shallow",
276
+ "sci_impact": "Reduces memory and rendering energy",
277
+ },
278
+ "avoid_tracking_unnecessary": {
279
+ "name": "Avoid Tracking Unnecessary Data",
280
+ "category": "web",
281
+ "keywords": ["tracking", "analytics", "telemetry", "unnecessary"],
282
+ "description": "Don't track data you won't use",
283
+ "sci_impact": "Reduces network and storage overhead",
284
+ },
285
+ "defer_offscreen_images": {
286
+ "name": "Defer Offscreen Images",
287
+ "category": "web",
288
+ "keywords": ["defer", "offscreen", "image", "lazy load", "viewport"],
289
+ "description": "Load images only when they enter viewport",
290
+ "sci_impact": "Reduces initial load energy and bandwidth",
291
+ },
292
+ "deprecate_gifs": {
293
+ "name": "Deprecate GIFs",
294
+ "category": "web",
295
+ "keywords": ["gif", "video", "webm", "mp4", "animation"],
296
+ "description": "Use video formats instead of animated GIFs",
297
+ "sci_impact": "Video formats are much more efficient than GIF",
298
+ },
299
+ "enable_text_compression": {
300
+ "name": "Enable Text Compression",
301
+ "category": "web",
302
+ "keywords": ["compress", "text", "gzip", "brotli", "minify"],
303
+ "description": "Compress HTML, CSS, JS before transmission",
304
+ "sci_impact": "Reduces bandwidth and transfer energy",
305
+ },
306
+ "keep_request_counts_low": {
307
+ "name": "Keep Request Counts Low",
308
+ "category": "web",
309
+ "keywords": ["request", "count", "http", "reduce", "combine"],
310
+ "description": "Minimize number of HTTP requests",
311
+ "sci_impact": "Lower network overhead per page load",
312
+ },
313
+ "minify_web_assets": {
314
+ "name": "Minify Web Assets",
315
+ "category": "web",
316
+ "keywords": ["minify", "minification", "uglify", "compress"],
317
+ "description": "Remove whitespace and unnecessary code",
318
+ "sci_impact": "Smaller files, less bandwidth",
319
+ },
320
+ "minimize_main_thread": {
321
+ "name": "Minimize Main Thread Work",
322
+ "category": "web",
323
+ "keywords": ["main thread", "worker", "offload", "javascript"],
324
+ "description": "Offload work from main thread to web workers",
325
+ "sci_impact": "Better CPU utilization, faster page loads",
326
+ },
327
+ "properly_sized_images": {
328
+ "name": "Properly Sized Images",
329
+ "category": "web",
330
+ "keywords": ["image", "size", "resize", "responsive", "srcset"],
331
+ "description": "Serve images at correct display size",
332
+ "sci_impact": "Avoids transferring and processing oversized images",
333
+ },
334
+ "remove_unused_css": {
335
+ "name": "Remove Unused CSS",
336
+ "category": "web",
337
+ "keywords": ["css", "unused", "purge", "tree shake"],
338
+ "description": "Eliminate CSS that isn't used on page",
339
+ "sci_impact": "Smaller CSS files, faster parsing",
340
+ },
341
+ "serve_modern_image_formats": {
342
+ "name": "Serve Images in Modern Formats",
343
+ "category": "web",
344
+ "keywords": ["webp", "avif", "image", "format", "modern"],
345
+ "description": "Use WebP or AVIF instead of JPEG/PNG",
346
+ "sci_impact": "Modern formats are significantly more efficient",
347
+ },
348
+ "server_side_rendering": {
349
+ "name": "Use Server-Side Rendering",
350
+ "category": "web",
351
+ "keywords": ["ssr", "server side", "rendering", "nextjs"],
352
+ "description": "Pre-render pages on server when appropriate",
353
+ "sci_impact": "Reduces client-side computation energy",
354
+ },
355
+ # ==================== AI/ML PATTERNS (10+) ====================
356
+ "compress_ml_models": {
357
+ "name": "Compress ML Models for Inference",
358
+ "category": "ai",
359
+ "keywords": ["compress", "model", "quantiz", "prune", "distill"],
360
+ "description": "Reduce model size through quantization, pruning, distillation",
361
+ "sci_impact": "Dramatically reduces inference energy and memory",
362
+ },
363
+ "efficient_format_training": {
364
+ "name": "Efficient Format for Model Training",
365
+ "category": "ai",
366
+ "keywords": ["format", "training", "tfrecord", "parquet", "efficient"],
367
+ "description": "Use efficient data formats for training",
368
+ "sci_impact": "Faster I/O, less storage, quicker training",
369
+ },
370
+ "energy_efficient_ai_edge": {
371
+ "name": "Energy Efficient AI at Edge",
372
+ "category": "ai",
373
+ "keywords": ["edge", "ai", "inference", "local", "device"],
374
+ "description": "Run inference on edge devices when possible",
375
+ "sci_impact": "Eliminates network transfer, uses local compute",
376
+ },
377
+ "energy_efficient_framework": {
378
+ "name": "Energy Efficient Framework",
379
+ "category": "ai",
380
+ "keywords": ["framework", "tensorflow", "pytorch", "efficient"],
381
+ "description": "Choose ML frameworks optimized for efficiency",
382
+ "sci_impact": "Different frameworks have different energy profiles",
383
+ },
384
+ "energy_efficient_models": {
385
+ "name": "Energy Efficient Models",
386
+ "category": "ai",
387
+ "keywords": ["model", "efficient", "mobilenet", "efficientnet"],
388
+ "description": "Use models designed for efficiency (e.g., MobileNet)",
389
+ "sci_impact": "Purpose-built efficient architectures",
390
+ },
391
+ "leverage_sustainable_regions_ai": {
392
+ "name": "Leverage Sustainable Regions for AI",
393
+ "category": "ai",
394
+ "keywords": ["region", "sustainable", "renewable", "carbon"],
395
+ "description": "Train models in regions with clean energy",
396
+ "sci_impact": "Lower carbon intensity for training",
397
+ },
398
+ "pretrained_transfer_learning": {
399
+ "name": "Pre-trained Transfer Learning",
400
+ "category": "ai",
401
+ "keywords": ["transfer", "learning", "pretrain", "fine-tune"],
402
+ "description": "Start from pre-trained models instead of training from scratch",
403
+ "sci_impact": "Avoids massive energy cost of full training",
404
+ },
405
+ "right_hardware_ai": {
406
+ "name": "Right Hardware Type for AI",
407
+ "category": "ai",
408
+ "keywords": ["hardware", "gpu", "tpu", "accelerator", "ai"],
409
+ "description": "Use appropriate hardware (GPU/TPU) for AI workloads",
410
+ "sci_impact": "Specialized hardware is more energy efficient",
411
+ },
412
+ "serverless_ml": {
413
+ "name": "Serverless Model Development",
414
+ "category": "ai",
415
+ "keywords": ["serverless", "ml", "sagemaker", "vertex", "lambda"],
416
+ "description": "Use serverless platforms for ML development",
417
+ "sci_impact": "Pay-per-use, no idle resources",
418
+ },
419
+ # ==================== GENERAL PATTERNS ====================
420
+ "autoscaling": {
421
+ "name": "Autoscaling",
422
+ "category": "cloud",
423
+ "keywords": ["autoscal", "scale", "elastic", "horizontal scaling", "hpa", "scaling policy"],
424
+ "description": "Automatically scale resources based on demand",
425
+ "sci_impact": "Reduces carbon emissions by matching resources to actual demand",
426
+ },
427
+ "optimize_storage": {
428
+ "name": "Optimize Storage",
429
+ "category": "cloud",
430
+ "keywords": ["compress", "deduplicate", "archive", "storage tier", "lifecycle policy"],
431
+ "description": "Reduce storage footprint through compression and deduplication",
432
+ "sci_impact": "Lower embodied carbon through reduced storage infrastructure",
433
+ },
434
+ "serverless": {
435
+ "name": "Use Serverless",
436
+ "category": "cloud",
437
+ "keywords": ["serverless", "lambda", "function", "faas", "cloud function"],
438
+ "description": "Use serverless computing for event-driven workloads",
439
+ "sci_impact": "Pay-per-use model ensures zero idle resource consumption",
440
+ },
441
+ "right_sizing": {
442
+ "name": "Right-size Resources",
443
+ "category": "cloud",
444
+ "keywords": [
445
+ "right-size",
446
+ "rightsize",
447
+ "downsize",
448
+ "optimize instance",
449
+ "resource optimization",
450
+ ],
451
+ "description": "Match compute resources to actual workload requirements",
452
+ "sci_impact": "Eliminates over-provisioning and reduces wasted energy",
453
+ },
454
+ # WEB PATTERNS
455
+ "lazy_loading": {
456
+ "name": "Lazy Loading",
457
+ "category": "web",
458
+ "keywords": ["lazy load", "lazy", "defer", "async", "on-demand"],
459
+ "description": "Load resources only when needed",
460
+ "sci_impact": "Reduces unnecessary data transfer and processing",
461
+ },
462
+ "minimize_data_transfer": {
463
+ "name": "Minimize Data Transfer",
464
+ "category": "web",
465
+ "keywords": ["minif", "compress", "gzip", "brotli", "optimize payload", "reduce bundle"],
466
+ "description": "Reduce size of data transferred over network",
467
+ "sci_impact": "Lower network energy consumption and faster load times",
468
+ },
469
+ "optimize_images": {
470
+ "name": "Optimize Images",
471
+ "category": "web",
472
+ "keywords": ["image optim", "webp", "responsive image", "lazy image", "compress image"],
473
+ "description": "Use efficient image formats and sizing",
474
+ "sci_impact": "Reduces bandwidth and storage requirements",
475
+ },
476
+ "reduce_http_requests": {
477
+ "name": "Reduce HTTP Requests",
478
+ "category": "web",
479
+ "keywords": ["bundle", "sprite", "inline", "combine", "reduce request"],
480
+ "description": "Minimize number of network requests",
481
+ "sci_impact": "Lower network overhead and latency",
482
+ },
483
+ # AI/ML PATTERNS
484
+ "model_optimization": {
485
+ "name": "Optimize ML Models",
486
+ "category": "ai",
487
+ "keywords": ["quantiz", "prune", "distill", "model compress", "optimize model"],
488
+ "description": "Reduce model size and complexity",
489
+ "sci_impact": "Dramatically reduces compute and memory requirements",
490
+ },
491
+ "batch_inference": {
492
+ "name": "Batch Inference",
493
+ "category": "ai",
494
+ "keywords": ["batch inference", "batch predict", "batch processing"],
495
+ "description": "Process ML predictions in batches",
496
+ "sci_impact": "More efficient GPU utilization",
497
+ },
498
+ # NETWORKING PATTERNS
499
+ "connection_pooling": {
500
+ "name": "Connection Pooling",
501
+ "category": "networking",
502
+ "keywords": ["connection pool", "pool", "reuse connection", "persistent connection"],
503
+ "description": "Reuse network connections instead of creating new ones",
504
+ "sci_impact": "Reduces connection overhead and resource consumption",
505
+ },
506
+ "rate_limiting": {
507
+ "name": "Rate Limiting",
508
+ "category": "networking",
509
+ "keywords": ["rate limit", "throttle", "backpressure", "circuit breaker"],
510
+ "description": "Control request rate to prevent resource exhaustion",
511
+ "sci_impact": "Prevents waste from processing excessive or malicious traffic",
512
+ },
513
+ # DATABASE PATTERNS
514
+ "database_indexing": {
515
+ "name": "Database Indexing",
516
+ "category": "database",
517
+ "keywords": ["index", "query optim", "explain", "slow query"],
518
+ "description": "Optimize database queries with proper indexing",
519
+ "sci_impact": "Reduces compute cycles for data retrieval",
520
+ },
521
+ "data_partitioning": {
522
+ "name": "Data Partitioning",
523
+ "category": "database",
524
+ "keywords": ["partition", "shard", "segment", "distribute data"],
525
+ "description": "Distribute data across multiple nodes",
526
+ "sci_impact": "Improves query efficiency and resource utilization",
527
+ },
528
+ # GENERAL PATTERNS
529
+ "async_processing": {
530
+ "name": "Asynchronous Processing",
531
+ "category": "general",
532
+ "keywords": ["async", "asynchronous", "non-blocking", "event-driven", "queue"],
533
+ "description": "Process tasks asynchronously to improve resource utilization",
534
+ "sci_impact": "Better CPU utilization and reduced idle time",
535
+ },
536
+ "resource_pooling": {
537
+ "name": "Resource Pooling",
538
+ "category": "general",
539
+ "keywords": ["thread pool", "worker pool", "object pool", "resource pool"],
540
+ "description": "Reuse expensive resources instead of creating new ones",
541
+ "sci_impact": "Reduces initialization overhead and memory pressure",
542
+ },
543
+ "memoization": {
544
+ "name": "Memoization",
545
+ "category": "general",
546
+ "keywords": ["memoize", "memoization", "cache result", "remember"],
547
+ "description": "Cache results of expensive function calls",
548
+ "sci_impact": "Avoids redundant computation",
549
+ },
550
+ "batch_processing": {
551
+ "name": "Batch Processing",
552
+ "category": "general",
553
+ "keywords": ["batch", "bulk", "batch insert", "batch update"],
554
+ "description": "Process multiple items together instead of one at a time",
555
+ "sci_impact": "Reduces per-item overhead and improves throughput",
556
+ },
557
+ }
558
+
559
+ # Green software keywords (comprehensive list from all GSF patterns)
560
+ GREEN_KEYWORDS = [
561
+ # Core sustainability terms
562
+ "energy",
563
+ "power",
564
+ "carbon",
565
+ "emission",
566
+ "footprint",
567
+ "sustainability",
568
+ "sustainable",
569
+ "green",
570
+ "efficient",
571
+ "efficiency",
572
+ "eco",
573
+ "environment",
574
+ "renewable",
575
+ # Performance & optimization
576
+ "optimize",
577
+ "optimization",
578
+ "optimise",
579
+ "optimisation",
580
+ "performance",
581
+ "performant",
582
+ "fast",
583
+ "faster",
584
+ "speed",
585
+ "speedup",
586
+ "latency",
587
+ "throughput",
588
+ "utilization",
589
+ # Caching & storage
590
+ "cache",
591
+ "caching",
592
+ "cached",
593
+ "redis",
594
+ "memcache",
595
+ "memcached",
596
+ "cdn",
597
+ "storage",
598
+ "compress",
599
+ "compression",
600
+ "compressed",
601
+ "gzip",
602
+ "brotli",
603
+ "zstd",
604
+ "deduplicate",
605
+ "dedup",
606
+ "archive",
607
+ "retention",
608
+ # Resource management
609
+ "pool",
610
+ "pooling",
611
+ "connection pool",
612
+ "thread pool",
613
+ "worker pool",
614
+ "resource pool",
615
+ "reuse",
616
+ "recycle",
617
+ "cleanup",
618
+ "garbage",
619
+ "remove unused",
620
+ "delete unused",
621
+ # Async & concurrency
622
+ "async",
623
+ "asynchronous",
624
+ "non-blocking",
625
+ "await",
626
+ "promise",
627
+ "queue",
628
+ "background",
629
+ "worker",
630
+ "job",
631
+ "batch",
632
+ "batching",
633
+ # Scaling & sizing
634
+ "scale",
635
+ "scaling",
636
+ "autoscale",
637
+ "autoscaling",
638
+ "elastic",
639
+ "elasticity",
640
+ "horizontal",
641
+ "vertical",
642
+ "right-size",
643
+ "rightsize",
644
+ "downsize",
645
+ "upsize",
646
+ "hpa",
647
+ "keda",
648
+ "demand",
649
+ "load",
650
+ # Cloud native
651
+ "serverless",
652
+ "lambda",
653
+ "function",
654
+ "faas",
655
+ "cloud function",
656
+ "container",
657
+ "docker",
658
+ "kubernetes",
659
+ "k8s",
660
+ "pod",
661
+ "microservice",
662
+ "service mesh",
663
+ "istio",
664
+ "envoy",
665
+ # Network optimization
666
+ "network",
667
+ "bandwidth",
668
+ "transmission",
669
+ "transfer",
670
+ "latency",
671
+ "proximity",
672
+ "region",
673
+ "closest",
674
+ "edge",
675
+ "cdn",
676
+ "rate limit",
677
+ "throttle",
678
+ "backpressure",
679
+ "circuit breaker",
680
+ "shed",
681
+ "reduce request",
682
+ "minimize request",
683
+ # Data & database
684
+ "index",
685
+ "indexing",
686
+ "query",
687
+ "optimize query",
688
+ "query optimization",
689
+ "partition",
690
+ "shard",
691
+ "database",
692
+ "db",
693
+ "sql",
694
+ "nosql",
695
+ # Web optimization
696
+ "minify",
697
+ "minification",
698
+ "uglify",
699
+ "tree shake",
700
+ "bundle",
701
+ "lazy load",
702
+ "defer",
703
+ "offscreen",
704
+ "viewport",
705
+ "dom",
706
+ "ssr",
707
+ "server side rendering",
708
+ "hydration",
709
+ "webp",
710
+ "avif",
711
+ "image",
712
+ "responsive",
713
+ # AI/ML
714
+ "model",
715
+ "quantiz",
716
+ "prune",
717
+ "pruning",
718
+ "distill",
719
+ "distillation",
720
+ "inference",
721
+ "training",
722
+ "pretrain",
723
+ "transfer learning",
724
+ "gpu",
725
+ "tpu",
726
+ "accelerator",
727
+ "mobilenet",
728
+ "efficientnet",
729
+ # Code & architecture
730
+ "stateless",
731
+ "decouple",
732
+ "independent",
733
+ "component",
734
+ "compiled",
735
+ "rust",
736
+ "go",
737
+ "c++",
738
+ "refactor",
739
+ "dead code",
740
+ "unused",
741
+ "deprecate",
742
+ # Security (energy-related)
743
+ "ddos",
744
+ "vulnerability",
745
+ "scan",
746
+ "security",
747
+ "waf",
748
+ # Monitoring & SLO
749
+ "slo",
750
+ "sla",
751
+ "metric",
752
+ "monitor",
753
+ "observability",
754
+ # Specific technologies
755
+ "redis",
756
+ "memcached",
757
+ "nginx",
758
+ "envoy",
759
+ "linkerd",
760
+ "karpenter",
761
+ "cluster autoscaler",
762
+ "spot instance",
763
+ "graviton",
764
+ "arm",
765
+ "architecture",
766
+ ]
767
+
768
+
769
+ def get_pattern_by_keywords(commit_message: str) -> list:
770
+ """
771
+ Match commit message against GSF patterns.
772
+
773
+ Args:
774
+ commit_message: The commit message to analyze
775
+
776
+ Returns:
777
+ List of matched pattern names
778
+ """
779
+ message_lower = commit_message.lower()
780
+ matched_patterns = []
781
+
782
+ for _pattern_id, pattern in GSF_PATTERNS.items():
783
+ for keyword in pattern["keywords"]:
784
+ if keyword.lower() in message_lower:
785
+ matched_patterns.append(pattern["name"])
786
+ break
787
+
788
+ return matched_patterns
789
+
790
+
791
+ def is_green_aware(commit_message: str) -> bool:
792
+ """
793
+ Check if commit shows green software awareness.
794
+
795
+ Args:
796
+ commit_message: The commit message to analyze
797
+
798
+ Returns:
799
+ True if commit contains green keywords
800
+ """
801
+ message_lower = commit_message.lower()
802
+ return any(keyword.lower() in message_lower for keyword in GREEN_KEYWORDS)