File size: 2,903 Bytes
24a2ddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import re

with open('D:/workAI/OpenCode/WorkSpace/backend-service/server.js', 'r', encoding='utf-8') as f:
    content = f.read()

# Remove all AXIS-DEBUG console.log lines (these are in generated HTML, run in browser)
# Match pattern: console.log('[AXIS-DEBUG]...');
# Handle both leading spaces and inline cases
content = re.sub(r"    console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
content = re.sub(r"      console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)
content = re.sub(r"        console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)

# Handle inline AXIS-DEBUG (e.g., if (x) { y; console.log('[AXIS-DEBUG]...'); })
content = re.sub(r"; console\.log\('\[AXIS-DEBUG\].*?'\);", "", content)

# Handle if with only AXIS-DEBUG: if (cond) console.log('[AXIS-DEBUG]...');
content = re.sub(r"      if \(.*?\) console\.log\('\[AXIS-DEBUG\].*?\);\n", "", content)

# Remove _rawToFormatted dead code block
# Find the block from comment to the end of forEach
pattern = r"    // .*?Build format map from chartData.*?\n    var _rawToFormatted = \{\};.*?}\n\}\);\n\n    // Build series elements"
content = re.sub(pattern, "    // Build series elements", content, flags=re.DOTALL)

# Remove verbose PIE DATA logging
content = content.replace(
    "    if (chartType === 'pie' || chartType === 'donut') {\n      console.log(`[WIDGET] renderChatGPTChart PIE DATA: data=${JSON.stringify(data)}, formattedData=${JSON.stringify(formattedData)}`);\n    }",
    ""
)

# Remove verbose nameKey/valueKey logging
content = content.replace(
    "    if (nameKey) console.log(`[WIDGET] renderChatGPTChart: nameKey=${nameKey}, valueKey=${valueKey}`);",
    ""
)

# Remove duplicate COLORS
old_colors = """    const COLORS = [
      '#339CFF', '#40C977', '#FF8549', '#FFD240',
      '#339CFF', '#40C977', '#FF8549', '#FFD240',
      '#339CFF', '#40C977', '#FF8549', '#FFD240',
    ];"""
new_colors = """    const COLORS = ['#339CFF', '#40C977', '#FF8549', '#FFD240'];"""
if old_colors in content:
    content = content.replace(old_colors, new_colors)

# Remove dead baseWaitTime/sizeWaitTime/totalWaitTime
content = re.sub(r"\n    const baseWaitTime = imgCount > 0.*?\n    const sizeWaitTime = imgSizeMB.*?\n    const totalWaitTime = Math\.min.*?\n", "\n", content)

# Remove redundant %%INJECTED_SCRIPTS%% placeholder
content = content.replace(".replace('%%INJECTED_SCRIPTS%%', '');", ";")

# Remove dead pieActualDataKey
content = content.replace("var pieActualDataKey = valueKey || chartSeries[0]?.dataKey || 'value';\n", "")

# Verify critical functions still present
if 'buildChatGPTChartHtml' in content and 'render_charts' in content and 'isAnimationActive: false' in content:
    with open('D:/workAI/OpenCode/WorkSpace/backend-service/server.js', 'w', encoding='utf-8') as f:
        f.write(content)
    print("SUCCESS: All cleanup applied")
else:
    print("ERROR: Critical content missing! NOT saving.")