nihalaninihal commited on
Commit
0ba32a7
·
verified ·
1 Parent(s): 00da473

Delete analyze_code_style.py

Browse files
Files changed (1) hide show
  1. analyze_code_style.py +0 -139
analyze_code_style.py DELETED
@@ -1,139 +0,0 @@
1
- from typing import Dict, Any, List, Tuple, Iterator
2
- import json
3
- from prompt_analyzer import create_handler
4
-
5
-
6
- def analyze_code_style(sources_data: Dict[str, Any]) -> Dict[str, Any]:
7
- """Analyzes developer's coding style patterns for stylometric analysis"""
8
-
9
- handler = create_handler()
10
- combined_results = {}
11
-
12
- for repo_name, repo_data in sources_data.items():
13
- print(f"\nAnalyzing repository: {repo_name}")
14
-
15
- prompt = f"""
16
-
17
- CODE STYLE ANALYSIS
18
-
19
- You are an expert in code stylometry and developer behavior analysis. Analyze this repository to create a detailed profile of the developer's coding patterns, preferences, and habits.
20
-
21
- Repository: {repo_name}
22
-
23
- Code samples and structure:
24
- {json.dumps(repo_data, indent=2)}
25
-
26
- Focus on identifying unique, individual coding patterns that could distinguish this developer's style. Analyze how they:
27
- - Structure their code and control flow
28
- - Handle data and state
29
- - Approach problem-solving
30
- - Maintain code quality
31
- - Handle edge cases and errors
32
-
33
- IMPORTANT CONSTRAINTS:
34
- - Maximum 10 patterns per list category
35
- - No repeating similar patterns
36
- - Use "Unknown" if pattern cannot be determined
37
- - Focus on distinctive, personal coding traits
38
-
39
- Generate a JSON profile with this EXACT structure:
40
-
41
- {{
42
- "code_organization": {{
43
- "file_structure": {{
44
- "preferred_file_size": number, // Average lines per file
45
- "module_organization": string, // e.g. "feature-based", "layer-based", "domain-based"
46
- "separation_patterns": [string] // Common ways they separate concerns
47
- }},
48
- "code_layout": {{
49
- "indentation": {{ "type": string, "width": number }},
50
- "line_length": {{ "average": number, "max_observed": number }},
51
- "spacing_style": {{
52
- "around_operators": string,
53
- "after_commas": boolean,
54
- "around_blocks": string
55
- }}
56
- }}
57
- }},
58
- "naming_patterns": {{
59
- "variables": {{
60
- "primary_style": string, // e.g. "snake_case", "camelCase"
61
- "consistency_score": number, // 0-100
62
- "length_preference": {{ "average": number, "range": [number, number] }},
63
- "semantic_patterns": [string] // How they choose names, e.g. "verb_noun_pairs", "hungarian_notation"
64
- }},
65
- "functions": {{
66
- "primary_style": string,
67
- "common_prefixes": [string],
68
- "common_patterns": [string],
69
- "length_preference": {{ "average": number, "range": [number, number] }}
70
- }}
71
- }},
72
- "coding_patterns": {{
73
- "control_flow": {{
74
- "preferred_loop_type": string, // e.g. "for", "while", "comprehension"
75
- "nesting_depth": {{ "average": number, "max_observed": number }},
76
- "branching_patterns": [string], // e.g. "early returns", "guard clauses"
77
- "condition_complexity": {{ "average": number, "max_observed": number }}
78
- }},
79
- "data_handling": {{
80
- "preferred_structures": [string], // Favorite data structures
81
- "mutation_patterns": {{
82
- "prefers_immutable": boolean,
83
- "common_patterns": [string]
84
- }},
85
- "state_management": {{
86
- "approach": string, // e.g. "functional", "stateful", "mixed"
87
- "patterns": [string]
88
- }}
89
- }}
90
- }},
91
- "error_handling": {{
92
- "strategy": string, // e.g. "defensive", "fail-fast", "hybrid"
93
- "patterns": [string], // Common error handling patterns
94
- "error_checking": {{
95
- "input_validation": boolean,
96
- "null_checking": boolean,
97
- "type_checking": boolean
98
- }}
99
- }},
100
- "code_quality": {{
101
- "documentation": {{
102
- "style": string, // e.g. "detailed", "minimal", "moderate"
103
- "coverage_ratio": number, // 0-100
104
- "preferred_formats": [string]
105
- }},
106
- "testing": {{
107
- "approach": string, // e.g. "unit-heavy", "integration-focused", "minimal"
108
- "patterns": [string]
109
- }},
110
- "complexity_metrics": {{
111
- "cyclomatic_complexity": {{ "average": number, "max_observed": number }},
112
- "cognitive_complexity": {{ "average": number, "max_observed": number }}
113
- }}
114
- }},
115
- "distinctive_traits": {{
116
- "unique_patterns": [string], // Highly individual coding patterns
117
- "favored_techniques": [string], // Preferred coding approaches
118
- "consistent_habits": [string] // Reliable behavioral patterns
119
- }}
120
- }}
121
-
122
- Critical requirements:
123
- 1. OUTPUT ONLY VALID JSON
124
- 2. NO markdown, NO comments, NO explanations
125
- 3. Use EXACT key names shown
126
- 4. All arrays MAXIMUM 10 items
127
- 5. Use numbers for metrics where specified
128
- 6. Use "Unknown" for undeterminable values
129
- """
130
-
131
- try:
132
- result = handler.generate_json_response(prompt)
133
- if result:
134
- combined_results[repo_name] = result
135
- except Exception as e:
136
- print(f"Error analyzing {repo_name}: {str(e)}")
137
- combined_results[repo_name] = {"error": str(e)}
138
-
139
- return combined_results