Created
October 8, 2020 14:39
-
-
Save k1000/c08ccb690f96767e29e0e56bcbca1c2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {AsyncStorage } from 'react-native'; | |
import {Actions} from 'react-native-router-flux'; | |
import Calendar from '../app/calendar'; | |
const moment = require('moment'); | |
const callib = require('./callib.js'); | |
const aspects = require('../data/favorable_days.json'); | |
const constellations = require('../data/constellations.json'); | |
const signsByNum = require('../data/signs_num.json'); | |
const signsByName = require('../data/tib_signs.json'); | |
import getData from './data'; | |
const signs = Object.keys(signsByName); | |
class Person { | |
locales = { | |
'en': 'English', | |
'ru': 'Pусский', | |
'it': 'Italiano', | |
'es': 'Español', | |
'fr': 'Français', | |
'pl': 'Polski', | |
'cs': 'Češky', | |
'pt': 'Português', | |
'gr': 'Ελληνικά', | |
'cn': 'Chinese', | |
'sk': 'Slovenský' | |
}; | |
constructor(){ | |
this.locale = 'en'; | |
this.pref_lang = this.locale; | |
this.animations_on = true; | |
this.signsByName = signsByName; | |
AsyncStorage.getItem('user').then((value) => { | |
if (value !== null) { | |
let obj = JSON.parse(value); | |
if ((obj.hasOwnProperty('name')) || (obj.hasOwnProperty('birthday'))){ | |
this.name = obj.hasOwnProperty('name') ? obj.name: ''; | |
//let birth_arr = obj.birthday.split('-'); | |
this.birth_arr = obj.birthday.split('-'); | |
this.birthday = obj.birthday; | |
this.animations_on = obj.hasOwnProperty('animations_on') ? obj.animations_on : this.animations_on; | |
this.locale = obj.hasOwnProperty('locale') ? obj.locale : this.locale; | |
this.pref_lang = obj.hasOwnProperty('pref_lang') ? obj.pref_lang : this.locale; | |
this.practitioner = obj.hasOwnProperty('practitioner') ? obj.practitioner: true; | |
this.calendar = new Calendar(this); | |
// go to calendar | |
this.getLang(this.locale, lang => { | |
this.setData(lang); | |
///debugger; | |
Actions.calendar({profile: this}); | |
}); | |
} else { | |
// go to profile edit | |
this.getLang(this.locale, function(lang) { | |
this.setData(lang); | |
Actions.profile_edit({profile: this}); | |
}); | |
} | |
} else { | |
// go to init | |
this.getLang(this.locale, function(lang) { | |
this.setData(lang); | |
Actions.intro({profile: this}); | |
}); | |
} | |
}).done(); | |
} | |
getLang(locale, callback){ | |
getData(locale, callback.bind(this)); //.bind(this) | |
} | |
setData = (lang) => { | |
this.locale = lang[0]; | |
this.lang = lang[1]; | |
if (this.name !== undefined) { | |
this.initialize(this.name, this.birth_arr); | |
} | |
//setTimeout(Actions.calendar({profile: this}), 1000); | |
} | |
setCalendar(){ | |
//let year = new Year(2017, 11, 8); | |
// let year = new Year(2018); | |
let calendar = new Calendar(this); | |
return calendar; | |
} | |
set(name, birth_date){ | |
this.initialize(name, birth_date); | |
} | |
setPractitioner(practitioner){ | |
this.practitioner = practitioner; | |
} | |
save(data, callback){ | |
let current_data = { | |
name: this.name, | |
birthday: this.birthday, | |
locale: this.locale, | |
animations_on: this.animations_on, | |
pref_lang: this.pref_lang, | |
practitioner: true | |
}; | |
// reasign mew data | |
Object.assign(current_data, data); | |
Object.assign(this, current_data); | |
this.birth_arr = current_data.birthday.split('-'); | |
this.getLang(current_data.pref_lang, (lang) => { | |
this.setData(lang); | |
this.locale = lang[0]; | |
current_data.locale = lang[0]; | |
if (current_data.pref_lang == this.locale) { | |
// we dont warry about delayed save | |
AsyncStorage.setItem('user', JSON.stringify(current_data), null); | |
} else { | |
alert('Sorry. We could not get your preferred language. English will be used instead. Please try again when you are online') | |
} | |
// we set caledar if it wasnt set before | |
if (!this.hasOwnProperty('calendar')) { | |
this.calendar = this.setCalendar(); | |
} | |
Actions.profile_view({profile: this}); | |
}); | |
} | |
initialize(name, birth_date) { | |
this.name = name; | |
this.birth_date = birth_date; | |
this.birth_year = this.birth_date[0] * 1; | |
this.birthday_date = moment(birth_date, 'YYYY-MM-DD'); | |
this.birth_tib_year = callib.get_tib_year(this.birthday_date); | |
// tib sign | |
this.birth_tib_sign = this.birth_tib_year.Animal; | |
this.birth_tib_sign_element = this.birth_tib_year.Ele; | |
this.birth_tib_sign_sex = this.birth_tib_year.Gender; | |
// Mewa | |
this.birth_mewa = callib.get_year_mewa(this.birth_year); | |
this.person_aspects = aspects[this.birth_tib_year.Animal]; | |
// weekdays | |
this.weekday = this.getWeekdays(this.person_aspects); | |
// birth constellations | |
this.constel = this.getConstellations(this.person_aspects); | |
// birth year aspects | |
this.birth_aspects = callib.get_year_aspects( | |
this.birth_tib_sign_element, this.birth_tib_sign); | |
let birthSignNum = signsByName[this.birth_tib_sign].num; | |
this.friends = this.getSignRelations(birthSignNum, 4); | |
//this.friends.pop(); // we have too much friends | |
this.oposite = this.getOpositeSign(birthSignNum); | |
this.donsurYear = this.oposite; | |
this.kegYear = this.birth_tib_sign; | |
this.foes = this.getSignRelations(birthSignNum, 3); | |
this.foes.push(this.birth_tib_sign); | |
let currDate = moment(); | |
this.currentYear = this.getAspectsForYear(currDate); | |
let nextDate = currDate.add(1, 'y'); | |
this.nextYear = this.getAspectsForYear(nextDate); | |
// this.birthSignRelationToCurrentYear = this.getBirthSignRelationToYear( | |
// this.birth_tib_sign, tibYear[2]); | |
// TODO favorable month days | |
} | |
getAspectsForYear(date){ | |
let tibYear = callib.get_tib_year(date); | |
let yearDeu = this.getDeuForYear(tibYear.Ele, tibYear.Animal); | |
let signRelation = this.getSignRelation(tibYear.Animal); | |
let eleRelation = this.getBirthElementRelation(tibYear.Ele, this.birth_tib_sign_element ); | |
return { | |
date: date, | |
tibYear: tibYear, | |
deu: yearDeu, | |
signRelation: signRelation, | |
eleRelation: eleRelation | |
}; | |
} | |
isKegYear(yearSign){ | |
return (this.kegYear === yearSign); | |
} | |
isDonsurYear(yearSign){ | |
return (this.donsurYear === yearSign); | |
} | |
getConstel(constelNum) { | |
let constel = constellations[constelNum]; | |
constel.num = constelNum; | |
return constel; | |
} | |
getConstellations(personAspects) { | |
return { | |
'vital_energy': this.getConstel(personAspects.constel_vital_ener), | |
'protective_energy': this.getConstel(personAspects.constel_protect_ener), | |
'potential_energy': this.getConstel(personAspects.constel_potential_ener), | |
'obstructive_energy': this.getConstel(personAspects.constel_obstructive_ener), | |
'impending_energy': this.getConstel(personAspects.constel_impending_ener), | |
'negative_energy': this.getConstel(personAspects.constel_negative_ener) | |
}; | |
} | |
getWeekdays(personAspects) { | |
return { | |
'auspicious': personAspects.auspicious, | |
'positive': personAspects.life_force, | |
'unfavourable': personAspects.unfavourable | |
}; | |
} | |
getDeuForYear(element, sign) { | |
this.year_aspects = callib.get_year_aspects(element, sign); | |
let deu = {}; | |
for (let aspect in this.birth_aspects) { | |
deu[aspect] = callib.get_ele_relation(this.birth_aspects[aspect],this.year_aspects[aspect]); | |
} | |
return deu; | |
} | |
getOpositeSign(signNum) { | |
return signs[ (signNum + 5) % 12 ] | |
} | |
getBirthElementRelation(ele1, ele2){ | |
let comparison = callib.get_ele_relation(ele1, ele2); | |
return comparison; | |
} | |
getSignRelations(signNum, distance){ | |
let relations = []; | |
let multiplier = Math.floor(12 / distance); | |
let sign = signs[signNum -1]; | |
for (var i = multiplier - 1; i >= 0; i--) { | |
//let relation = (12 + signNum + (i * distance) - 5) % 12; | |
let relation = signs[(signNum -1 + (i * distance)) % 12] | |
if (relation !== sign) { | |
relations.push(relation) | |
} | |
} | |
return relations; | |
} | |
getShiShey(signNum) { | |
let relation1 = (12 + signNum + 3 - 5) % 12; | |
let relation2 = (12 + signNum - 3 - 5) % 12; | |
return [ | |
signsByNum[relation1].name, | |
signsByNum[relation2].name, | |
]; | |
} | |
getSignRelation(sign){ | |
if (this.oposite === sign) return 'oposite'; | |
if (this.friends.find((x) => {return (x === sign)}) ) return 'friend'; | |
if (this.foes.find((x) => {return (x === sign)}) ) return 'foe'; | |
return 'neutral'; | |
} | |
} | |
module.exports = Person; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment