-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
111 lines (80 loc) · 3.17 KB
/
api.ts
File metadata and controls
111 lines (80 loc) · 3.17 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import {type Base, type Connection, type ConnectionType, type House, type Planet, type Sign} from "./models.ts";
// import {dataMock} from "./data";
import {dataMock} from "./shared/sample_data";
import {signElements} from "./common.ts";
export interface DataCombined {
base: Base;
planets: Planet[];
houses: House[];
signs: Sign[];
connections: Connection[];
label: string;
labels: string[];
}
export async function getData(getParams: any, mock: boolean = false): Promise<DataCombined> {
let data = dataMock;
if (!mock) {
var url = new URL('https://bodygraph.online/api_v1/astro.php')
url.search = new URLSearchParams(getParams).toString();
console.log('requesting', url.toString());
const res = await fetch(url).then(res => res.json());
data = res.data;
}
// console.log(JSON.stringify(data));
const base = data.base;
let planets: Planet[] = [];
for (let name of Object.keys(data.inner_circle)) {
const angle = (data.inner_circle as any)[name].angle;
// if (['Паллас',"Церес","Земля","Веста"].includes(name)) continue;
planets.push({name, angle: angle, color: 'black', shift: 0});
}
const signNames = [ 'Рыбы', 'Овен', 'Телец', 'Близнецы', 'Рак', 'Лев', 'Дева', 'Весы', 'Скорпион', 'Стрелец','Козерог', 'Водолей'];
const signs: Sign[] = [];
for (let i = 0; i < 12; i++) {
const name = signNames[i];
const element = signElements[(i+2) % 4];
signs.push({name, angle: i * 30 - 13.8, element});
}
const houses: House[] = [];
for (let name of Object.keys(data.outer_circle)) {
const house = (data.outer_circle as any)[name]
houses.push({name: house.name, angle: house.angle});
}
const connections: Connection[] = [];
for (let dCon of data.connections) {
let type: ConnectionType | undefined = undefined;
if (dCon.type.startsWith("Полу")) {
type = "Полу-секстиль";
} else if (dCon.type.startsWith("Тригон")) {
type = "Трин";
} else if (dCon.type.startsWith("Кенконс")) {
type = "Квиконс";
} else if (dCon.type.startsWith("Секстиль")) {
type = "Секстиль";
} else if (dCon.type.startsWith("Квадратура")) {
type = "Квадратура";
} else if (dCon.type.startsWith("Оппозиция")) {
type = "Оппозиция";
} else if (dCon.type.startsWith("Соединение")) {
type = "Соединение";
} else {
console.error("Невизестный тип соединения", dCon.type);
}
function getPlanet(name: string) {
return planets.find((a) => a.name === name);
}
const fromPlanet = getPlanet(dCon.from);
const toPlanet = getPlanet(dCon.to);
if (type && fromPlanet && toPlanet) {
if (type=="Соединение"){
// fromPlanet.color = "blue"
// toPlanet.color = "blue"
toPlanet.shift += 1;
}
connections.push({from: fromPlanet, to: toPlanet, type});
}
}
const label = data.label;
const labels = data.labels;
return {base, planets, houses, signs, connections, label, labels}
}