Browse Source

增加星宿数据

master
hejl 2 weeks ago
parent
commit
c2b1733743
  1. 195
      win_text_editor/lib/modules/pdf_parse/services/excel_data_adjustment_service.dart
  2. 5
      win_text_editor/lib/modules/pdf_parse/services/excel_deal_service.dart
  3. 107
      win_text_editor/lib/modules/pdf_parse/services/relationship_calculator_service.dart

195
win_text_editor/lib/modules/pdf_parse/services/excel_data_adjustment_service.dart

@ -16,6 +16,131 @@ class ExcelDataAdjustmentService { @@ -16,6 +16,131 @@ class ExcelDataAdjustmentService {
'': 330,
};
// 宿宿
static const List<Map<String, dynamic>> starConstellations = [
{'name': '', 'start': 34.342, 'end': 47.315}, // 34°20'32" -> 34.342°, 47°18'52" -> 47.315°
{'name': '', 'start': 47.315, 'end': 59.795}, // 47°18'52" -> 47.315°, 59°47'43" -> 59.795°
{'name': '', 'start': 59.795, 'end': 68.863}, // 59°47'43" -> 59.795°, 68°51'47" -> 68.863°
{'name': '', 'start': 68.863, 'end': 84.063}, // 68°51'47" -> 68.863°, 84°03'48" -> 84.063°
{'name': '', 'start': 84.063, 'end': 85.064}, // 84°03'48" -> 84.063°, 85°03'51" -> 85.064°
{'name': '', 'start': 85.064, 'end': 95.680}, // 85°03'51" -> 85.064°, 95°40'47" -> 95.680°
{'name': '', 'start': 95.680, 'end': 126.129}, // 95°40'47" -> 95.680°, 126°07'46" -> 126.129°
{'name': '', 'start': 126.129, 'end': 131.118}, // 126°07'46" -> 126.129°, 131°07'06" -> 131.118°
{'name': '', 'start': 131.118, 'end': 147.100}, // 131°07'06" -> 131.118°, 147°06'02" -> 147.100°
{'name': '', 'start': 147.100, 'end': 155.092}, // 147°06'02" -> 147.100°, 155°05'30" -> 155.092°
{'name': '', 'start': 155.092, 'end': 174.165}, // 155°05'30" -> 155.092°, 174°09'53" -> 174.165°
{'name': '', 'start': 174.165, 'end': 191.096}, // 174°09'53" -> 174.165°, 191°05'46" -> 191.096°
{'name': '', 'start': 191.096, 'end': 203.901}, // 191°05'46" -> 191.096°, 203°54'05" -> 203.901°
{'name': '', 'start': 203.901, 'end': 214.888}, // 203°54'05" -> 203.901°, 214°53'14" -> 214.888°
{'name': '', 'start': 214.888, 'end': 225.477}, // 214°53'14" -> 214.888°, 225°28'37" -> 225.477°
{'name': '', 'start': 225.477, 'end': 243.325}, // 225°28'37" -> 225.477°, 243°19'30" -> 243.325°
{'name': '', 'start': 243.325, 'end': 248.175}, // 243°19'30" -> 243.325°, 248°10'29" -> 248.175°
{'name': '', 'start': 248.175, 'end': 256.429}, // 248°10'29" -> 248.175°, 256°25'44" -> 256.429°
{'name': '', 'start': 256.429, 'end': 271.624}, // 256°25'44" -> 256.429°, 271°37'27" -> 271.624°
{'name': '', 'start': 271.624, 'end': 280.561}, // 271°37'27" -> 271.624°, 280°33'40" -> 280.561°
{'name': '', 'start': 280.561, 'end': 304.477}, // 280°33'40" -> 280.561°, 304°28'37" -> 304.477°
{'name': '', 'start': 304.477, 'end': 312.144}, // 304°28'37" -> 304.477°, 312°08'39" -> 312.144°
{'name': '', 'start': 312.144, 'end': 323.812}, // 312°08'39" -> 312.144°, 323°48'42" -> 323.812°
{'name': '', 'start': 323.812, 'end': 333.781}, // 323°48'42" -> 323.812°, 333°46'51" -> 333.781°
{'name': '', 'start': 333.781, 'end': 353.851}, // 333°46'51" -> 333.781°, 353°51'04" -> 353.851°
{'name': '', 'start': 353.851, 'end': 10.603}, // 353°51'04" -> 353.851°, 10°36'11" -> 10.603°
{'name': '', 'start': 10.603, 'end': 22.824}, // 10°36'11" -> 10.603°, 22°49'26" -> 22.824°
{'name': '', 'start': 22.824, 'end': 34.342}, // 22°49'26" -> 22.824°, 34°20'32" -> 34.342°
];
// 宿
String getStarConstellation(double degrees) {
// 0
for (final constellation in starConstellations) {
final start = constellation['start'] as double;
final end = constellation['end'] as double;
if (start <= end) {
// start < end
if (degrees >= start && degrees < end) {
return constellation['name'] as String;
}
} else {
// 0start > end353.851° -> 10.603°
if (degrees >= start || degrees < end) {
return constellation['name'] as String;
}
}
}
return ''; // 宿
}
//
double? _extractDegreesFromCell(String cellValue) {
if (cellValue.isEmpty) return null;
// R/D
String cleanedValue = cellValue.replaceAll(RegExp(r'[RD]'), '');
cleanedValue = cleanedValue.replaceAll(RegExp(r'[""]+'), ''); //
//
// 1: "15°30'45" "15°30"
var match = RegExp(r"^(\d+)\s*°\s*(\d+)\s*(?:['′]\s*(\d{1,2})\s*)?$").firstMatch(cleanedValue);
if (match != null) {
try {
final degrees = int.parse(match.group(1)!);
final minutes = int.parse(match.group(2)!);
final seconds = match.group(3) != null ? int.parse(match.group(3)!) : 0;
//
return degrees + (minutes / 60.0) + (seconds / 3600.0);
} catch (e) {
return null;
}
}
// 2: "15.5°" "15.5"
match = RegExp(r"^(\d+\.?\d*)\s*°?\s*$").firstMatch(cleanedValue);
if (match != null) {
try {
return double.parse(match.group(1)!);
} catch (e) {
return null;
}
}
// 3: "15" ()
match = RegExp(r"^(\d+)\s*$").firstMatch(cleanedValue);
if (match != null) {
try {
return double.parse(match.group(1)!);
} catch (e) {
return null;
}
}
//
print(' - 清理后值: "$cleanedValue" (无法匹配任何度数格式)');
return null;
}
//
String _getColumnTitle(int colIndex) {
const Map<int, String> columnTitles = {
4: '',
5: '',
6: '',
7: '',
8: '',
9: '',
10: '',
11: '',
12: '',
13: '',
14: '',
15: '',
16: '',
17: '',
};
return columnTitles[colIndex] ?? '未知';
}
static final _degreeFormatRegex = RegExp(
r"^(\d+)\s*([^\d\s°']+)\s*(\d+)\s*(?:['′]\s*(\d{1,2})\s*)?$",
caseSensitive: false,
@ -31,11 +156,14 @@ class ExcelDataAdjustmentService { @@ -31,11 +156,14 @@ class ExcelDataAdjustmentService {
) {
List<String?> currentRowPalaces = List.filled(14, null);
int outputCol = startCol; // 使
// 宿
bool isDebugRow = rowIndex < 5;
for (int col = 4; col <= 17 && col < cells.length; col++) {
final cellValue = cells[col];
//
// 1.
final palace = _extractPalace(cellValue);
String palaceToWrite = palace;
@ -47,17 +175,58 @@ class ExcelDataAdjustmentService { @@ -47,17 +175,58 @@ class ExcelDataAdjustmentService {
previousPalaces[col] = palaceToWrite;
}
currentRowPalaces[col - 4] = palaceToWrite;
// 2.
final displayValue = _getFormattedValueWithAdjustment(cellValue, palaceToWrite);
// 3. 宿
String palaceWithConstellation = palaceToWrite;
String starConstellation = '';
double? adjustedDegrees = null;
if (palaceToWrite.isNotEmpty) {
//
adjustedDegrees = _extractDegreesFromCell(displayValue);
if (adjustedDegrees != null) {
starConstellation = getStarConstellation(adjustedDegrees);
if (starConstellation.isNotEmpty) {
palaceWithConstellation = '$palaceToWrite$starConstellation';
}
}
// 宿
if (isDebugRow) {
final columnTitle = _getColumnTitle(col);
final originalDegrees = _extractDegreesFromCell(cellValue);
if (adjustedDegrees != null) {
print('${rowIndex + 1}${columnTitle}: 原始坐标${originalDegrees?.toStringAsFixed(3) ?? "未知"}° -> 宫位:$palaceToWrite -> 修正后坐标${adjustedDegrees.toStringAsFixed(3)}° -> 星宿:$starConstellation -> 结果:$palaceWithConstellation');
} else {
print('${rowIndex + 1}${columnTitle}: 无法解析修正后坐标 -> 宫位:$palaceToWrite, 星宿:$starConstellation -> 结果:$palaceWithConstellation');
//
print(' - 原始值: "$cellValue"');
print(' - 修正后值: "$displayValue"');
print(' - 宫位: "$palaceToWrite"');
//
final originalDegrees = _extractDegreesFromCell(cellValue);
if (originalDegrees != null) {
print(' - 原始值可提取度数: ${originalDegrees.toStringAsFixed(3)}°');
} else {
print(' - 原始值无法提取度数');
}
}
}
}
currentRowPalaces[col - 4] = palaceWithConstellation;
//
// 4. 宿
sheet.cell(CellIndex.indexByColumnRow(
columnIndex: outputCol,
rowIndex: rowIndex
)).value = TextCellValue(palaceToWrite);
)).value = TextCellValue(palaceWithConstellation);
outputCol++;
//
final displayValue = _getFormattedValueWithAdjustment(cellValue, palaceToWrite);
// 5.
sheet.cell(CellIndex.indexByColumnRow(
columnIndex: outputCol,
rowIndex: rowIndex
@ -86,11 +255,21 @@ class ExcelDataAdjustmentService { @@ -86,11 +255,21 @@ class ExcelDataAdjustmentService {
adjusted = _adjustDegreeByPalace(withDegreeSymbol, palace);
}
// 4. R/D
return rdFlags.isNotEmpty ? '$adjusted$rdFlags' : adjusted;
// 4. R/D
String result = rdFlags.isNotEmpty ? '$adjusted$rdFlags' : adjusted;
//
result = result.replaceAll(RegExp(r'[""]+'), '"');
return result;
}
String _replaceZodiacWithDegreeSymbol(String value) {
//
if (value.contains('°')) {
return value; //
}
final match = _degreeFormatRegex.firstMatch(value);
if (match == null) return value;

5
win_text_editor/lib/modules/pdf_parse/services/excel_deal_service.dart

@ -90,7 +90,7 @@ class ExcelDealService { @@ -90,7 +90,7 @@ class ExcelDealService {
// 2. 5-18
for (int col = 4; col <= 17 && col < cells.length; col++) {
final title = _columnTitles[col] ?? '';
extendedCells.add('${title}');
extendedCells.add('${title}'); // 宿
extendedCells.add(cells[col]);
}
@ -110,7 +110,8 @@ class ExcelDealService { @@ -110,7 +110,8 @@ class ExcelDealService {
}
void _setColumnWidths(Sheet sheet) {
// + +
// + +宿 +
// 2+宿
for (var i = 0; i < 4 + (_columnTitles.length * 2) + 3; i++) {
sheet.setColumnWidth(i, 8.0);
}

107
win_text_editor/lib/modules/pdf_parse/services/relationship_calculator_service.dart

@ -3,7 +3,6 @@ import 'package:excel/excel.dart'; @@ -3,7 +3,6 @@ import 'package:excel/excel.dart';
class RelationshipCalculatorService {
final Map<String, bool> _columnRedStates = {};
final List<List<String>> _aspects = []; // Stores [conjunction, opposition, square, hui, banhe] for each row
int _debugRowCount = 0; //
final Map<String, int> _columnIndexes = {}; //
static const List<String> zodiacColumns = [
@ -25,7 +24,6 @@ class RelationshipCalculatorService { @@ -25,7 +24,6 @@ class RelationshipCalculatorService {
void processEntireSheet(Sheet sheet) {
_columnRedStates.clear();
_aspects.clear();
_debugRowCount = 0; //
_columnIndexes.clear(); //
//
@ -138,7 +136,7 @@ class RelationshipCalculatorService { @@ -138,7 +136,7 @@ class RelationshipCalculatorService {
void _calculateCoordinateRelationships(List<Data?> row) {
List<int> positionsInMinutes = [];
List<String> planets = [];
bool isDebugRow = _debugRowCount > 4 && _debugRowCount < 10;
// Extract positions for all planets in minutes
for (int i = 0; i < zodiacColumns.length; i++) {
final columnTitle = zodiacColumns[i];
@ -182,10 +180,6 @@ class RelationshipCalculatorService { @@ -182,10 +180,6 @@ class RelationshipCalculatorService {
List<String> huis = []; //
List<String> banhes = []; // 60°360
if (isDebugRow) {
print('=== 第${_debugRowCount + 1}行相位计算 ===');
}
for (int i = 0; i < positionsInMinutes.length; i++) {
for (int j = i + 1; j < positionsInMinutes.length; j++) {
final diff = (positionsInMinutes[i] - positionsInMinutes[j]).abs();
@ -194,8 +188,6 @@ class RelationshipCalculatorService { @@ -194,8 +188,6 @@ class RelationshipCalculatorService {
// 使
final degI = positionsInMinutes[i] ~/ 60;
final degJ = positionsInMinutes[j] ~/ 60;
final degDiff = circularDiff / 60.0; //
//
if ((planets[i] == '' && planets[j] == '') ||
@ -203,81 +195,34 @@ class RelationshipCalculatorService { @@ -203,81 +195,34 @@ class RelationshipCalculatorService {
continue; //
}
// 3
if (isDebugRow) {
//
final degIComplete = positionsInMinutes[i] / 60.0;
final degJComplete = positionsInMinutes[j] / 60.0;
String output = '${planets[i]}(${degIComplete.toStringAsFixed(2)}°) vs ${planets[j]}(${degJComplete.toStringAsFixed(2)}°) - 差值: ${degDiff.toStringAsFixed(2)}°';
// Check for conjunction (0°±30 minutes 120°±30 minutes)
if (circularDiff <= 30 || (circularDiff >= 7170 && circularDiff <= 7290)) {
// 0°00' to 0°30' 119°30' to 120°29'
conjunctions.add('${planets[i]}${planets[j]}');
output += ' → 合相位';
}
// Check for square (90°±30 minutes)
// 89°30' = 5370分钟,90°29' = 5429
else if (circularDiff >= 5370 && circularDiff <= 5429) {
// 89°30' to 90°29'
squares.add('${planets[i]}${planets[j]}');
output += ' → 刑相位';
}
// Check for opposition (180°±30 minutes)
else if (circularDiff >= 10770 && circularDiff <= 10890) {
// 179°30' to 180°29'
oppositions.add('${planets[i]}${planets[j]}');
output += ' → 冲相位';
}
//
else if (degI == degJ) {
huis.add('${planets[i]}${planets[j]}');
output += ' → 会相位';
}
// 60°±3059°30'到60°29'
// 59°30' = 3570分钟,60°29' = 3629
else if (circularDiff >= 3570 && circularDiff <= 3629) {
banhes.add('${planets[i]}${planets[j]}半合');
output += ' → 半合相位';
}
print(output);
} else {
//
// Check for conjunction (0°±30 minutes 120°±30 minutes)
if (circularDiff <= 30 || (circularDiff >= 7170 && circularDiff <= 7290)) {
// 0°00' to 0°30' 119°30' to 120°29'
conjunctions.add('${planets[i]}${planets[j]}');
}
// Check for square (90°±30 minutes)
// 89°30' = 5370分钟,90°29' = 5429
else if (circularDiff >= 5370 && circularDiff <= 5429) {
// 89°30' to 90°29'
squares.add('${planets[i]}${planets[j]}');
}
// Check for opposition (180°±30 minutes)
else if (circularDiff >= 10770 && circularDiff <= 10890) {
// 179°30' to 180°29'
oppositions.add('${planets[i]}${planets[j]}');
}
//
else if (degI == degJ) {
huis.add('${planets[i]}${planets[j]}');
}
// 60°±3059°30'到60°29'
// 59°30' = 3570分钟,60°29' = 3629
else if (circularDiff >= 3570 && circularDiff <= 3629) {
banhes.add('${planets[i]}${planets[j]}半合');
}
// Check for conjunction (0°±30 minutes 120°±30 minutes)
if (circularDiff <= 30 || (circularDiff >= 7170 && circularDiff <= 7290)) {
// 0°00' to 0°30' 119°30' to 120°29'
conjunctions.add('${planets[i]}${planets[j]}');
}
// Check for square (90°±30 minutes)
// 89°30' = 5370分钟,90°29' = 5429
else if (circularDiff >= 5370 && circularDiff <= 5429) {
// 89°30' to 90°29'
squares.add('${planets[i]}${planets[j]}');
}
// Check for opposition (180°±30 minutes)
else if (circularDiff >= 10770 && circularDiff <= 10890) {
// 179°30' to 180°29'
oppositions.add('${planets[i]}${planets[j]}');
}
//
else if (degI == degJ) {
huis.add('${planets[i]}${planets[j]}');
}
// 60°±3059°30'到60°29'
// 59°30' = 3570分钟,60°29' = 3629
else if (circularDiff >= 3570 && circularDiff <= 3629) {
banhes.add('${planets[i]}${planets[j]}半合');
}
}
}
if (isDebugRow) {
print('--- 第${_debugRowCount + 1}行计算完成 ---\n');
}
_aspects.add([
conjunctions.join(', '),
oppositions.join(', '),
@ -285,8 +230,6 @@ class RelationshipCalculatorService { @@ -285,8 +230,6 @@ class RelationshipCalculatorService {
huis.join(', '),
banhes.join(', '),
]);
_debugRowCount++; //
}
void _addAspectMarkers(Sheet sheet) {

Loading…
Cancel
Save