Commit 505e0a11 authored by Jack Stupple's avatar Jack Stupple

tweak import and also add french emily questions

parent e8cc5396
......@@ -13,11 +13,28 @@ class Character extends Model
'enabled' => 'datetime'
];
protected $appends = ['available_questions'];
public function baseModifiers()
{
return $this->hasMany(Modifier::class, 'model_id')->where('model', '=', 'character');
}
public function getAvailableQuestionsAttribute()
{
$player = get_player($_SERVER['HTTP_SESSION_ID'], false);
if ($player->language_id) {
$language = \App\Language::where('id', $player->language_id)->firstOrFail();
} else {
$language = \App\Language::where('slug', 'en')->first();
}
return $this->questions()
->where('language_id', $language->id)
->count();
}
public function questions()
{
return $this->hasMany(Question::class);
......
......@@ -10,12 +10,10 @@ class ImportEmilyQuestions extends CharacterMigration
protected $character;
protected $language;
static $cache = [];
static $base_modifiers = '/resources/data/emily/base-modifiers.json';
static $questions = '/resources/data/emily/questions.json';
static $season_roundups = '/resources/data/emily/season-roundups.json';
static $profile_pictures = '/resources/data/emily/profile-pictures.json';
protected $base_modifiers = '/resources/data/emily/base-modifiers.json';
protected $questions = '/resources/data/emily/questions.json';
protected $season_roundups = '/resources/data/emily/season-roundups.json';
protected $profile_pictures = '/resources/data/emily/profile-pictures.json';
/**
* Run the migrations.
......@@ -25,27 +23,12 @@ class ImportEmilyQuestions extends CharacterMigration
public function up()
{
$this->created_at = date('Y-m-d H:i:s');
// test importing emily in french
$this->language = \App\Language::where('slug', 'en')->first();
$this->character = new \App\Character();
$this->character->name = 'Emily';
$this->character->enabled = $this->created_at;
$this->character->save();
$this->profilePictures(APP_ROOT . static::$profile_pictures);
$this->baseModifiers(APP_ROOT . static::$base_modifiers);
$this->questions(APP_ROOT . static::$questions);
$this->seasonRoundups(APP_ROOT . static::$season_roundups);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// truncate all the tables?
$this->import();
}
}
......@@ -10,12 +10,10 @@ class ImportJamalsQuestions extends CharacterMigration
protected $character;
protected $language;
static $cache = [];
static $base_modifiers = '/resources/data/jamal/base-modifiers.json';
static $questions = '/resources/data/jamal/questions.json';
static $season_roundups = '/resources/data/jamal/season-roundups.json';
static $profile_pictures = '/resources/data/jamal/profile-pictures.json';
protected $base_modifiers = '/resources/data/jamal/base-modifiers.json';
protected $questions = '/resources/data/jamal/questions.json';
protected $season_roundups = '/resources/data/jamal/season-roundups.json';
protected $profile_pictures = '/resources/data/jamal/profile-pictures.json';
/**
* Run the migrations.
......@@ -25,16 +23,12 @@ class ImportJamalsQuestions extends CharacterMigration
public function up()
{
$this->created_at = date('Y-m-d H:i:s');
$this->language = \App\Language::where('slug', 'en')->first();
$this->character = new \App\Character();
$this->character->name = 'Jamal';
$this->character->enabled = $this->created_at;
$this->character->save();
$this->profilePictures(APP_ROOT . static::$profile_pictures);
$this->baseModifiers(APP_ROOT . static::$base_modifiers);
$this->questions(APP_ROOT . static::$questions);
$this->seasonRoundups(APP_ROOT . static::$season_roundups);
$this->import();
}
}
......@@ -15,7 +15,6 @@ class AddSocialText extends Migration
*/
public function up()
{
$this->language = \App\Language::where('slug', 'en')->first();
foreach (['emily', 'jake', 'jamal', 'ann'] as $_character) {
$character = \App\Character::where('name', 'LIKE', $_character)->first();
$json_path = APP_ROOT . '/resources/data/' . $_character . '/social-statuses.json';
......@@ -24,15 +23,23 @@ class AddSocialText extends Migration
continue;
}
foreach (json_decode(file_get_contents($json_path)) as $_status) {
$status = new \App\CharacterSocial();
$status->character_id = $character->id;
$status->language_id = $this->language->id;
$status->body = $_status->body;
$status->likes = $_status->likes;
$status->comments = $_status->comments;
$status->season_roundup_position = $_status->season_roundup_position;
$status->save();
$statuses = json_decode(file_get_contents($json_path), 1);
foreach (\App\Language::whereRaw('enabled <= NOW()')->get() as $language) {
if (!isset($statuses[$language->slug])) {
continue;
}
foreach ($statuses[$language->slug] as $_status) {
$status = new \App\CharacterSocial();
$status->character_id = $character->id;
$status->language_id = $language->id;
$status->body = $_status['body'];
$status->likes = $_status['likes'];
$status->comments = $_status['comments'];
$status->season_roundup_position = $_status['season_roundup_position'];
$status->save();
}
}
}
}
......
......@@ -13,26 +13,60 @@ use Illuminate\Database\Migrations\Migration;
*/
class CharacterMigration extends Migration
{
protected function profilePictures($json_location)
static $cache = [];
protected function import()
{
if (!file_exists($json_location)) return false;
$questions = $season_roundups = $profile_pictures = $base_modifiers = [];
if (isset($this->questions) && file_exists(APP_ROOT . $this->questions)) {
$questions = json_decode(file_get_contents(APP_ROOT . $this->questions), 1);
}
if (isset($this->season_roundups) && file_exists(APP_ROOT . $this->season_roundups)) {
$season_roundups = json_decode(file_get_contents(APP_ROOT . $this->season_roundups), 1);
}
if (isset($this->profile_pictures) && file_exists(APP_ROOT . $this->profile_pictures)) {
$profile_pictures = json_decode(file_get_contents(APP_ROOT . $this->profile_pictures), 1);
$this->profilePictures($profile_pictures);
}
if (isset($this->base_modifiers) && file_exists(APP_ROOT . $this->base_modifiers)) {
$base_modifiers = json_decode(file_get_contents(APP_ROOT . $this->base_modifiers), 1);
$this->modifiers($base_modifiers);
}
$languages = \App\Language::whereRaw('enabled <= NOW()')->get();
foreach ($languages as $language) {
$this->language = $language;
foreach (json_decode(file_get_contents($json_location)) as $_profile_picture) {
if (isset($questions[$this->language->slug])) {
$this->questions($questions[$this->language->slug]);
}
if (isset($season_roundups[$this->language->slug])) {
$this->seasonRoundups($season_roundups[$this->language->slug]);
}
}
}
protected function profilePictures($profile_pictures)
{
foreach ($profile_pictures as $_profile_picture) {
$profile_picture = new \App\CharacterPicture();
$profile_picture->character_id = $this->character->id;
$profile_picture->uri = 'data:image/png;base64,' . base64_encode(file_get_contents(APP_ROOT . '/resources/assets/characters/' . strtolower($this->character->name) . '/profile-pictures/' . $_profile_picture->uri));
$profile_picture->season_roundup_position = $_profile_picture->season_roundup_position;
$profile_picture->uri = 'data:image/png;base64,' . base64_encode(file_get_contents(APP_ROOT . '/resources/assets/characters/' . strtolower($this->character->name) . '/profile-pictures/' . $_profile_picture['uri']));
$profile_picture->season_roundup_position = $_profile_picture['season_roundup_position'];
$profile_picture->save();
}
}
protected function baseModifiers($json_location)
protected function modifiers($modifiers)
{
if (!file_exists($json_location)) return false;
foreach (json_decode(file_get_contents($json_location), 1) as $_base_modifier) {
$_category = $_base_modifier['category'];
$amount = $_base_modifier['amount'];
foreach ($modifiers as $_modifier) {
$_category = $_modifier['category'];
$amount = $_modifier['amount'];
$income_outgoing = 'outgoing';
if ($_category == 'salary') {
......@@ -58,11 +92,9 @@ class CharacterMigration extends Migration
}
}
protected function questions($json_location)
protected function questions($questions)
{
if (!file_exists($json_location)) return false;
foreach (json_decode(file_get_contents($json_location), 1) as $_question) {
foreach ($questions as $_question) {
$question_category = \App\QuestionCategory::where('name', 'LIKE', $_question['question_category'])->first();
$question = new \App\Question;
......@@ -116,11 +148,9 @@ class CharacterMigration extends Migration
}
}
protected function seasonRoundups($json_location)
protected function seasonRoundups($season_roundups)
{
if (!file_exists($json_location)) return false;
foreach (json_decode(file_get_contents($json_location), 1) as $_roundup) {
foreach ($season_roundups as $_roundup) {
$roundup = new \App\SeasonRoundup;
$roundup->language_id = $this->language->id;
$roundup->roundup_text = $_roundup['roundup_text'];
......
This diff is collapsed.
[
{
"roundup_text": "Due to recent electricity price hikes, Emily's utility bills have increased.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 8
}
]
},
{
"roundup_text": "Emily signs up for a course that will enable her to get a more rewarding job and career in the future.",
"positive_negative": -1,
"modifiers": [
{
"category": "other_out",
"amount": 22
}
]
},
{
"roundup_text": "Emily played bass on her friend's album and is now getting a small amount of income from an online streaming service.",
"positive_negative": 1,
"modifiers": [
{
"category": "other_in",
"amount": 3.8
}
]
},
{
"roundup_text": "Emily decides to cancel her subscriptions to film and TV streaming services.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -8
}
]
},
{
"roundup_text": "Emily goes on a health kick and decides to eat better, increasing the cost of her groceries.",
"positive_negative": -1,
"modifiers": [
{
"category": "groceries",
"amount": 7
}
]
},
{
"roundup_text": "Emily has been turning up for work tired, so decides to stop going out as much during the week.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -80
}
]
},
{
"roundup_text": "Emily's flat mate, Rosie, loses her job. Emily decides to help Rosie with some of her share of the rent.",
"positive_negative": -1,
"modifiers": [
{
"category": "rent",
"amount": 70
}
]
},
{
"roundup_text": "Emily starts dating someone and the relationship is going well, all those romantic dinners mean Emily's entertainment costs have increased.",
"positive_negative": -1,
"modifiers": [
{
"category": "entertainment",
"amount": 30
}
]
},
{
"roundup_text": "Emily's washing machine breaks down, her landlord quickly replaces it meaning she doesn't have to pay extra to get her laundry done. Phew!",
"positive_negative": 1,
"modifiers": []
}
]
{
"en": [
{
"roundup_text": "Due to recent electricity price hikes, Emily's utility bills have increased.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 8
}
]
},
{
"roundup_text": "Emily signs up for a course that will enable her to get a more rewarding job and career in the future.",
"positive_negative": -1,
"modifiers": [
{
"category": "other_out",
"amount": 22
}
]
},
{
"roundup_text": "Emily played bass on her friend's album and is now getting a small amount of income from an online streaming service.",
"positive_negative": 1,
"modifiers": [
{
"category": "other_in",
"amount": 3.8
}
]
},
{
"roundup_text": "Emily decides to cancel her subscriptions to film and TV streaming services.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -8
}
]
},
{
"roundup_text": "Emily goes on a health kick and decides to eat better, increasing the cost of her groceries.",
"positive_negative": -1,
"modifiers": [
{
"category": "groceries",
"amount": 7
}
]
},
{
"roundup_text": "Emily has been turning up for work tired, so decides to stop going out as much during the week.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -80
}
]
},
{
"roundup_text": "Emily's flat mate, Rosie, loses her job. Emily decides to help Rosie with some of her share of the rent.",
"positive_negative": -1,
"modifiers": [
{
"category": "rent",
"amount": 70
}
]
},
{
"roundup_text": "Emily starts dating someone and the relationship is going well, all those romantic dinners mean Emily's entertainment costs have increased.",
"positive_negative": -1,
"modifiers": [
{
"category": "entertainment",
"amount": 30
}
]
},
{
"roundup_text": "Emily's washing machine breaks down, her landlord quickly replaces it meaning she doesn't have to pay extra to get her laundry done. Phew!",
"positive_negative": 1,
"modifiers": []
}
],
"fr": [
{
"roundup_text": "En raison des hausses récentes des prix de l'électricité, les factures d'électricité d'Emily ont augmenté.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 8
}
]
},
{
"roundup_text": "Emily s'inscrit à un cours qui lui permettra d'obtenir un emploi et une carrière plus enrichissante à l'avenir.",
"positive_negative": -1,
"modifiers": [
{
"category": "other_out",
"amount": 22
}
]
},
{
"roundup_text": "Emily a joué de la basse sur l'album de son ami et reçoit maintenant une petite quantité de revenus d'un service de streaming en ligne.",
"positive_negative": 1,
"modifiers": [
{
"category": "other_in",
"amount": 3.8
}
]
},
{
"roundup_text": "Emily décide d'annuler ses abonnements aux services de diffusion de films et de télévision.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -8
}
]
},
{
"roundup_text": "Emily prend un coup de pied santé et décide de mieux manger, ce qui augmente le coût de ses courses.",
"positive_negative": -1,
"modifiers": [
{
"category": "groceries",
"amount": 7
}
]
},
{
"roundup_text": "Emily est venue fatigué au travail, alors décide d'arrêter de sortir autant pendant la semaine.",
"positive_negative": 1,
"modifiers": [
{
"category": "entertainment",
"amount": -80
}
]
},
{
"roundup_text": "La colocataire d'Emily, Rosie, perd son travail. Emily décide d'aider Rosie avec une partie de sa part du loyer.",
"positive_negative": -1,
"modifiers": [
{
"category": "rent",
"amount": 70
}
]
},
{
"roundup_text": "Emily commence à sortir avec quelqu'un et la relation se passe bien, tous ces dîners romantiques signifient que les coûts de divertissement d'Emily ont augmenté.",
"positive_negative": -1,
"modifiers": [
{
"category": "entertainment",
"amount": 30
}
]
},
{
"roundup_text": "La machine à laver d'Emily tombe en panne, son propriétaire la remplace rapidement, ce qui signifie qu'elle n'a pas à payer plus pour faire la lessive. Phew!",
"positive_negative": 1,
"modifiers": []
}
]
}
[
{
"body": "Hoping to go on a big adventure holiday next year with my BFF! 🗺 Need to save some 💰💰 tho 🤞",
"season_roundup_position": 0,
"likes": 9,
"comments": 31
},
{
"body": "Buzzing from our gig last night. Big turn out which always helps us enjoy performing 🎸🤘",
"season_roundup_position": 1,
"likes": 16,
"comments": 4
},
{
"body": "Feeling sick 🤮 So not up for going out tonight. Anyone want my ticket to the show?",
"season_roundup_position": 2,
"likes": 3,
"comments": 12
}
]
{
"en": [
{
"body": "Hoping to go on a big adventure holiday next year with my BFF! 🗺 Need to save some 💰💰 tho 🤞",
"season_roundup_position": 0,
"likes": 9,
"comments": 31
},
{
"body": "Buzzing from our gig last night. Big turn out which always helps us enjoy performing 🎸🤘",
"season_roundup_position": 1,
"likes": 16,
"comments": 4
},
{
"body": "Feeling sick 🤮 So not up for going out tonight. Anyone want my ticket to the show?",
"season_roundup_position": 2,
"likes": 3,
"comments": 12
}
],
"fr": [
{
"body": "En espérant faire de grandes vacances d'aventure l'année prochaine avec mon BFF! 🗺 Besoin d'économiser du temps 💰💰 tho 🤞",
"season_roundup_position": 0,
"likes": 9,
"comments": 31
},
{
"body": "Bourdonnement de notre concert la nuit dernière. Un grand tournant qui nous aide toujours à performer 🎸🤘",
"season_roundup_position": 1,
"likes": 16,
"comments": 4
},
{
"body": "Je me sens malade 🤮 Donc pas prêt à sortir ce soir. Quelqu'un veut mon billet pour le spectacle?",
"season_roundup_position": 2,
"likes": 3,
"comments": 12
}
]
}
This diff is collapsed.
[
{
"roundup_text": "Jamal's boiler has broken down and needs to be replaced. He has to use his credit card to pay for the new boiler and for a plumber to fit it.",
"positive_negative": -1,
"modifiers": [
{
"category": "credit cards \/ loans",
"amount": 30
}
]
},
{
"roundup_text": "Jamal has been overpaying tax so he receives a lump sum for the overpayment. His salary is recalculated too so he doesn't overpay going forward.",
"positive_negative": 1,
"modifiers": [
{
"category": "salary",
"amount": 40
}
]
},
{
"roundup_text": "The family decides to get a pet, so Jamal will need to take out some insurance and buy pet food.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 15
},
{
"category": "groceries",
"amount": 20
}
]
},
{
"roundup_text": "Jamal agrees to get his kids the latest children's TV channel which is a subscription service.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 8
}
]
},
{
"roundup_text": "Jamal's wife gets a small increase in her wages meaning she can contribute more to household bills.",
"positive_negative": 1,
"modifiers": [
{
"category": "bills",
"amount": -50
}
]
},
{
"roundup_text": "The family decides to get a smart speaker, but Jamal has to update his music subscription to a family plan for everyone to use it.",
"positive_negative": -1,
"modifiers": [
{
"category": "bills",
"amount": 5
}
]
},
{
"roundup_text": "Jamal gets a supermarket membership card that helps him save money on his groceries.",
"positive_negative": 1,
"modifiers": [
{
"category": "groceries",
"amount": -20
}
]
},
{
"roundup_text": "The government has announced their new budget, petrol prices have gone up considerably as a result.",
"positive_negative": -1,
"modifiers": [
{
"category": "transport",