MCPcopy Create free account
hub / github.com/chokcoco/iCSS / analyzeLabelRelations

Method analyzeLabelRelations

MCP/scripts/fetch-issues.js:299–359  ·  view source on GitHub ↗
(issues)

Source from the content-addressed store, hash-verified

297 }
298
299 async analyzeLabelRelations(issues) {
300 console.log('📊 Analyzing label relations...');
301
302 const labelPairs = new Map();
303 const labelCounts = new Map();
304
305 // 收集标签共现信息
306 for (const issue of issues) {
307 try {
308 const labels = Array.isArray(issue.labels)
309 ? issue.labels.map(label => typeof label === 'string' ? label : label.name)
310 : JSON.parse(issue.labels || '[]');
311
312 // 更新单个标签计数
313 labels.forEach(label => {
314 labelCounts.set(label, (labelCounts.get(label) || 0) + 1);
315 });
316
317 // 更新标签对的共现计数
318 for (let i = 0; i < labels.length; i++) {
319 for (let j = i + 1; j < labels.length; j++) {
320 const pair = [labels[i], labels[j]].sort().join('->');
321 labelPairs.set(pair, (labelPairs.get(pair) || 0) + 1);
322 }
323 }
324 } catch (error) {
325 console.error(`Error processing labels for issue #${issue.number}:`, error);
326 continue;
327 }
328 }
329
330 // 计算相关性分数并更新数据库
331 const updateRelationSQL = `
332 INSERT OR REPLACE INTO label_relations
333 (label1, label2, cooccurrence_count, correlation_score, last_updated)
334 VALUES (?, ?, ?, ?, datetime('now'))
335 `;
336
337 for (const [pair, count] of labelPairs.entries()) {
338 try {
339 const [label1, label2] = pair.split('->');
340 const correlation = count / Math.sqrt(labelCounts.get(label1) * labelCounts.get(label2));
341
342 await new Promise((resolve, reject) => {
343 this.db.run(
344 updateRelationSQL,
345 [label1, label2, count, correlation],
346 (err) => {
347 if (err) reject(err);
348 else resolve();
349 }
350 );
351 });
352 } catch (error) {
353 console.error(`Error saving relation for pair ${pair}:`, error);
354 continue;
355 }
356 }

Callers 1

saveIssuesToDatabaseMethod · 0.95

Calls 3

setMethod · 0.80
getMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected