Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pure_php/convert_speaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
'ended_at' => 0,
'room' => '',
'floor' => '',
'sponsor' => [],
'sponsor_id' => 0,
'sponsor_info' => [],
];

$file = $argv[1];
Expand Down Expand Up @@ -145,4 +146,12 @@
ksort($data);

file_put_contents($target, json_encode(array_values($data), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));

usort($tagCollect, function ($data) {
if (in_array($data['name'], ['Mobile App', 'AI', 'IoT'])) {
return -1;
}
return 1;
});

file_put_contents(str_replace('.json', '-tags.json', $target), json_encode(array_values($tagCollect), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
119 changes: 114 additions & 5 deletions pure_php/convert_sponsor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,60 @@
* $ php conver_sponsor.php input_tsv output_json
*/

// mapping data
$sponsor_type = [
'Tony Stark' => 'tony_stark',
'Bruce Wayne' => 'bruce_wayne',
'Hacker' => 'hacker',
'Developer' => 'developer',
'其他' => 'special_thanks',
];

$special_sponsor_type = [
79 => 'education'
];

$sponsor_type_name = [
'tony_stark' => [
'name' => 'Tony Stark',
'name_e' => 'Tony Stark',
'icon' => 'BruceWayne',
],
'bruce_wayne' => [
'name' => 'Bruce Wayne',
'name_e' => 'Bruce Wayne',
'icon' => 'BruceWayne',
],
'hacker' => [
'name' => 'Hacker',
'name_e' => 'Hacker',
'icon' => 'Hacker',
],
'developer' => [
'name' => 'Developer',
'name_e' => 'Developer',
'icon' => 'Developer',
],
'education' => [
'name' => '教育贊助',
'name_e' => 'Education Sponsor',
'icon' => 'Other',
],
'special_thanks' => [
'name' => '特別感謝',
'name_e' => 'Special Thanks',
'icon' => 'Other',
],
];

$sponsor_type_sort = array_flip(array_keys($sponsor_type_name));

// sponsor id => speaker id
$sponsor_speaker = [
70 => 182,
71 => 189
];

$extraField = [
'career_information' => '',
];
Expand All @@ -16,8 +70,10 @@
$data = [];
$producionData = file_exists($target) ? json_decode(file_get_contents($target), true) : [];
if (count($producionData) > 0) {
foreach ($producionData as $sponsor) {
$data[$sponsor['sponsor_id']] = $sponsor;
foreach ($producionData as $sponsorGroup) {
foreach ($sponsorGroup['data'] as $sponsor) {
$data[$sponsor['sponsor_id']] = $sponsor;
}
}
}

Expand Down Expand Up @@ -45,15 +101,16 @@
$result[2] = preg_replace('/ /', '_', $result[3]);

$newData = [
"logo_path" => 'api/' . $result[1] . '/sponsor/images/sponsor_' . $result[0],
"logo_path" => 'assets/images/sponsors/' . $result[0] . '.png',
"name" => $result[4],
"name_e" => $result[5],
"sponsor_id" => (int) $result[0],
"about_us" => $result[6],
"about_us_e" => $result[7],
"facebook_url" => $result[9],
"official_website" => $result[8],
"sponsor_type" => $result[3],
"sponsor_type" => $special_sponsor_type[(int) $result[0]] ?? $sponsor_type[$result[3]],
"speaker_information" => [],
];

if (array_key_exists($newData['sponsor_id'], $data)) {
Expand All @@ -66,4 +123,56 @@

ksort($data);

file_put_contents($target, json_encode(array_values($data), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
$speaker_file = $argv[3];
if (file_exists($speaker_file) && count($sponsor_speaker) > 0) {
// mapping speakers
$speakers = [];
foreach (json_decode(file_get_contents($speaker_file), true) as $speaker) {
$speakers[$speaker['speaker_id']] = $speaker;
}

foreach ($sponsor_speaker as $sponsor_id => $speaker_id) {
$speakers[$speaker_id]['sponsor_id'] = $sponsor_id;
$speakers[$speaker_id]['sponsor_info'] = [
"logo_path" => $data[$sponsor_id]["logo_path"],
"name" => $data[$sponsor_id]["name"],
"name_e" => $data[$sponsor_id]["name_e"]
];

$data[$sponsor_id]['speaker_information'][] = $speakers[$speaker_id];
file_put_contents(
$speaker_file,
json_encode(array_values($speakers), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
);
}
}

usort($data, function ($a, $b) use ($sponsor_type_sort) {
if ($sponsor_type_sort[$a['sponsor_type']] == $sponsor_type_sort[$b['sponsor_type']]) {
return 0;
}
return $sponsor_type_sort[$a['sponsor_type']] > $sponsor_type_sort[$b['sponsor_type']] ? 1 : -1;
});

$group_data = [];
$img_data = [];

foreach ($data as $sponsor) {
$group_data[$sponsor['sponsor_type']]['data'][] = $sponsor;
$img_data[] = [
"logo_path" => $sponsor["logo_path"],
"name" => $sponsor["name"],
"name_e" => $sponsor["name_e"],
"sponsor_id" => $sponsor["sponsor_id"],
];
}

foreach ($sponsor_type_name as $key => $names) {
if (!isset($group_data[$key]['data'])) {
continue;
}
$group_data[$key] = array_merge($names, $group_data[$key]);
}

file_put_contents($target, json_encode(array_values($group_data), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
file_put_contents('sponsor-img.json', json_encode(array_values($img_data), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
36 changes: 29 additions & 7 deletions pure_php/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
]],
['str' => '10:00', 'end' => '10:10', 'event' => '休息 Break', 'isBroadCast' => false],
['str' => '10:10', 'end' => '10:55', 'event' => '', 'isBroadCast' => false, 'room' => [
'2021004' => [106],
'2021004' => [107],
'2021005' => [111],
'2021006' => [110],
]],
['str' => '10:55', 'end' => '11:05', 'event' => '休息 Break', 'isBroadCast' => false],
['str' => '11:05', 'end' => '11:50', 'event' => '', 'isBroadCast' => false, 'room' => [
'2021007' => [107],
'2021007' => [106],
'2021008' => [140],
'2021009' => [142],
]],
Expand Down Expand Up @@ -77,7 +77,7 @@
'2021032' => [181],
'2021033' => [117],
]],
['str' => '11:00', 'end' => '13:00', 'event' => '午餐 Lunch', 'isBroadCast' => false],
['str' => '12:00', 'end' => '13:00', 'event' => '午餐 Lunch', 'isBroadCast' => false],
['str' => '13:00', 'end' => '13:45', 'event' => '', 'isBroadCast' => false, 'room' => [
'2021034' => [108],
'2021035' => [182],
Expand Down Expand Up @@ -107,7 +107,14 @@
];

$arrange = [];
$mappingSpeaker = function ($session_id, $speaker_ids, array $speakersArr, $room_number) {
$mappingSpeaker = function (
$session_id,
$speaker_ids,
array $speakersArr,
$room_number,
$started_at,
$ended_at
) {
// default
$tmpRoom = [
'session_id' => $session_id,
Expand All @@ -124,6 +131,8 @@
'prior_knowledge' => '',
'expected_gain' => '',
'tags' => '',
"started_at" => $started_at,
"ended_at" => $ended_at,
];
foreach ($speaker_ids as $speaker_id) {
$tmpRoom = [
Expand All @@ -141,6 +150,10 @@
'prior_knowledge' => $speakersArr[$speaker_id]['prior_knowledge'] ?? '',
'expected_gain' => $speakersArr[$speaker_id]['expected_gain'] ?? '',
'tags' => $speakersArr[$speaker_id]['tags'] ?? '',
'sponsor_id' => $speakersArr[$speaker_id]['sponsor_id'] ?? 0,
'sponsor' => $speakersArr[$speaker_id]['sponsor_info'] ?? [],
"started_at" => $started_at,
"ended_at" => $ended_at,
];
$speakers[] = [
'speaker_id' => $speaker_id ?? 0,
Expand Down Expand Up @@ -182,7 +195,16 @@
foreach ($session['room'] as $session_id => $speaker_ids) {
$session_count = (int) substr($session_id, -2);
$room_number = "R" . ($session_count % 3 == 0 ? 3 : $session_count % 3);
$room[] = $mappingSpeaker($session_id, $speaker_ids, $speakersArr, $room_number);
$started_at = isset($session['str']) ? (int) strtotime($date . ' ' . $session['str']) : 0;
$ended_at = isset($session['end']) ? (int) strtotime($date . ' ' . $session['end']) : 0;
$room[] = $mappingSpeaker(
$session_id,
$speaker_ids,
$speakersArr,
$room_number,
$started_at,
$ended_at
);
// 將對應資料存回講者
foreach ($speaker_ids as $speaker_id) {
$speakersArr[$speaker_id]['room'] = $room_number;
Expand All @@ -194,7 +216,7 @@
}
$day["period"][] = [
'started_at' => $started_at,
'isBroadCast' => true,
'isBroadCast' => $session['isBroadCast'],
'ended_at' => $ended_at,
'event' => $session['event'] ?? '',
'room' => $room,
Expand All @@ -204,4 +226,4 @@
}

file_put_contents('./schedule.json', json_encode(array_values($arrange), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
file_put_contents('./speakers.json', json_encode(array_values($speakersArr), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
file_put_contents($file, json_encode(array_values($speakersArr), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
42 changes: 42 additions & 0 deletions pure_php/sort_speaker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* $ php convert_speaker.php speakers.tsv speaker.json
*/

$file = $argv[1];
$target = $argv[2];
if (!file_exists($file) || !file_exists($target)) {
echo "File not found";
die();
}
$data = [];
$productionData = json_decode(file_get_contents($target), true);
if (count($productionData) > 0) {
foreach ($productionData as $speaker) {
$data[$speaker['speaker_id']] = $speaker;
}
}

$f = fopen($file, 'r');
$firstLine = true;

$sort = [];
while (($row = fgets($f)) !== false) {
if ($firstLine) {
$firstLine = false;
continue;
}
$line = explode("\t", $row);
$sort[(int) $line[4]] = $line[0];
print_r($line);
}

usort($data, function ($a, $b) use ($sort) {
if ($sort[$a['speaker_id']] === $sort[$b['speaker_id']]) {
return 0;
}
return $sort[$a['speaker_id']] > $sort[$b['speaker_id']] ? 1 : -1;
});

file_put_contents(str_replace('.json', '-sort.json', $target), json_encode(array_values($data), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));