Skip to content

Commit

Permalink
Make the dates better; no one cares what the year is.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasyn authored and Xander Johnson committed Nov 8, 2019
1 parent 6b58001 commit 4271f36
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/js/components/dates/DateSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { formatDate } from '../util';

export default class DateSelector extends Component {
constructor(props) {
Expand Down Expand Up @@ -36,7 +37,7 @@ export default class DateSelector extends Component {
value={date}
checked={this.state.isChecked}
onChange={this.handleChange}
/> {date}
/> {formatDate(date)}
</div>
);
}
Expand Down
56 changes: 28 additions & 28 deletions src/js/components/parser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import $ from "jquery";
import $ from 'jquery';

import Venues from "../../data/venues.json";
import { getEditDistance } from "./util";
import Venues from '../../data/venues.json';
import { getEditDistance, formatDate } from './util';

export default class Parser {
constructor() {
this.list = "https://metasyn.pw/s/shows.json";
this.list = 'https://metasyn.pw/s/shows.json';
}

parseData() {
return fetch(this.list)
.then(r => r.json())
.then(data => {
.then((data) => {
const organized = Parser.sortByDateForReal(data);
const dates = Parser.getDates(organized);
const geojson = Parser.geojsonify(organized);
Expand All @@ -23,6 +23,7 @@ export default class Parser {

static getDates(organized) {
const dates = [];
// eslint-disable-next-line array-callback-return
Object.keys(organized).map((x, i) => {
dates.push({ id: i, date: $.trim(x), checked: true });
});
Expand All @@ -31,7 +32,7 @@ export default class Parser {

static sortByDateForReal(data) {
const organized = {};
for (let i = 0; i < data.length; i++) {
for (let i = 0; i < data.length; i += 1) {
if (!organized[data[i].date]) {
organized[data[i].date] = [];
}
Expand All @@ -49,23 +50,23 @@ export default class Parser {

// Array is zero indexed but nth-child starts at 1
const index = i + 1;
const $shows = $results.find(`body > li:nth-child(${index})`).find("li");
const $shows = $results.find(`body > li:nth-child(${index})`).find('li');

for (let si = 0; si < $shows.length; si += 1) {
const things = [];
$($shows[si])
.find("a")
.find('a')
.each((_, x) => {
things.push($.trim(x.text));
});

const deets = $.trim($shows[si].innerText.split("\n").slice(-3, -2));
const deets = $.trim($shows[si].innerText.split('\n').slice(-3, -2));

organized[dates[i].date].push({
venue: things.shift(),
date: dates[i].date,
details: deets,
artists: things
artists: things,
});
}
}
Expand All @@ -89,44 +90,43 @@ export default class Parser {
if (!Venues[showData.venue]) {
try {
for (let v = 0; v < venueList.length; v += 1) {
const misspelled = showData.venue.replace(/\W/g, "");
const spelledCorrect = venueList[v].replace(/\W/g, "");
const misspelled = showData.venue.replace(/\W/g, '');
const spelledCorrect = venueList[v].replace(/\W/g, '');
const editDistance = getEditDistance(misspelled, spelledCorrect);
if (editDistance <= 3) {
console.log(
`"${showData.venue}" has been replaced with "${venueList[v]}"`
);
console.log(`'${showData.venue}' has been replaced with '${venueList[v]}'`);
showData.venue = venueList[v];
}
}
} catch (e) {
console.log("Missing Venue?", e);
console.log('Missing Venue?', e);
}
}

const showString = `${dateKeys[i]} - ${
const formattedDate = formatDate(dateKeys[i]);
const showString = `${formattedDate} - ${
showData.venue
} | ${showData.artists.join(" | ")} | ${showData.details}`;
} | ${showData.artists.join(' | ')} | ${showData.details}`;
const artistsString = showData.artists
.map(x => `- ${x} <br/>`)
.join("");
const showHTML = `<h2> ${dateKeys[i]} </h2><br/><h3> ${artistsString}<br/> ${showData.details}</h3>`;
.join('');
const showHTML = `<h2> ${formattedDate} </h2><br/><h3> ${artistsString}<br/> ${showData.details}</h3>`;

const show = {
type: "Feature",
type: 'Feature',
geometry: {
type: "Point",
coordinates: Venues[showData.venue] || [-122.42296, 37.826524]
type: 'Point',
coordinates: Venues[showData.venue] || [-122.42296, 37.826524], // alcatraz
},
properties: {
sid: `${i}-${j}`,
date: dateKeys[i],
venue: showData.venue,
artists: showData.artists,
details: showData.details.replace(/ ,/g, ""), // fucking commas
details: showData.details.replace(/ ,/g, ''), // fucking commas
showString,
showHTML
}
showHTML,
},
};

// add show to features array
Expand All @@ -136,8 +136,8 @@ export default class Parser {

// format for valid geojson
const geojson = {
type: "FeatureCollection",
features
type: 'FeatureCollection',
features,
};
return geojson;
}
Expand Down
19 changes: 19 additions & 0 deletions src/js/components/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import {DateTime} from 'luxon';

// Compute the edit distance between the two given strings
export function getEditDistance(a, b) {
Expand Down Expand Up @@ -95,3 +96,21 @@ export function getMinMaxDates(dates) {
maxTime,
};
}

export function getWeekDay(date) {
// Create an array containing each day, starting with Sunday.
const weekdays = [
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
];
// Use the getDay() method to get the day.
const day = date.getDay();
// Return the element that corresponds to that index.
return weekdays[day];
}

export function formatDate(dateString) {
const date = DateTime.fromISO(dateString); // force pacific timezone
date.setZone('America/Los_Angeles');
return `${date.weekdayShort}, ${date.month}-${date.day}`;
}

0 comments on commit 4271f36

Please sign in to comment.