-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Tweet metric methods * Add TweetsController with views * Linting fix * Add charts * Sort Gemfile * Align side title with vh * Linting fix * Renove redundand highsharts script from the app template
- Loading branch information
Showing
21 changed files
with
593 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class TweetsController < ApplicationController | ||
def index | ||
@tweets = Tweet.first(10).map(&:decorate) | ||
|
||
respond_to do |format| | ||
format.html # renders index.html.slim | ||
end | ||
end | ||
|
||
def show | ||
@tweet = Tweet.find(params[:id]).decorate | ||
|
||
respond_to do |format| | ||
format.html # renders show.html.slim | ||
format.json do | ||
# TODO: add filtering by date range and by metrics subset | ||
render json: @tweet.tweet_metrics.to_json | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ApplicationDecorator < Draper::Decorator | ||
# Define methods for all decorated objects. | ||
# Helpers are accessed through `helpers` (aka `h`). For example: | ||
# | ||
# def percent_amount | ||
# h.number_to_percentage object.amount, precision: 2 | ||
# end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
class TweetDecorator < Draper::Decorator | ||
delegate_all | ||
|
||
def combined_chart | ||
h.area_chart combined_metrics_series, height: "20vh", library: chart_options | ||
end | ||
|
||
def likes_chart | ||
h.line_chart( | ||
likes_metric[:data], | ||
min: min_y(likes_metric), | ||
max: max_y(likes_metric), | ||
height: "70vh", | ||
library: single_metric_chart_options("Likes") | ||
) | ||
end | ||
|
||
def replies_chart | ||
h.line_chart( | ||
replies_metric[:data], | ||
min: min_y(replies_metric), | ||
max: max_y(replies_metric), | ||
height: "70vh", | ||
library: single_metric_chart_options("Replies") | ||
) | ||
end | ||
|
||
def reposts_chart | ||
h.line_chart( | ||
reposts_metric[:data], | ||
min: min_y(reposts_metric), | ||
max: max_y(reposts_metric), | ||
height: "70vh", | ||
library: single_metric_chart_options("Reposts") | ||
) | ||
end | ||
|
||
def bookmarks_chart | ||
h.line_chart( | ||
bookmarks_metric[:data], | ||
min: min_y(bookmarks_metric), | ||
max: max_y(bookmarks_metric), | ||
height: "70vh", | ||
library: single_metric_chart_options("Bookmarks") | ||
) | ||
end | ||
|
||
def views_chart | ||
h.line_chart( | ||
views_metric[:data], | ||
min: min_y(views_metric), | ||
max: max_y(views_metric), | ||
height: "70vh", | ||
library: single_metric_chart_options("Views") | ||
) | ||
end | ||
|
||
private | ||
|
||
def min_y(metric) | ||
metric[:data].min_by { |k, v| k.to_i }&.last | ||
end | ||
|
||
def max_y(metric) | ||
metric[:data].max_by { |k, v| k.to_i }&.last | ||
end | ||
|
||
def single_metric_chart_options(title) | ||
chart_options.merge( | ||
yAxis: { | ||
title: { | ||
text: title | ||
} | ||
} | ||
) | ||
end | ||
|
||
def chart_options | ||
{ | ||
chart: { | ||
zoomType: "xy" | ||
}, | ||
resetZoomButton: { | ||
theme: { | ||
display: "flex" | ||
} | ||
} | ||
} | ||
end | ||
|
||
def combined_metrics_series | ||
[ | ||
likes_metric, | ||
replies_metric, | ||
reposts_metric, | ||
bookmarks_metric, | ||
views_metric | ||
] | ||
end | ||
|
||
def likes_metric | ||
@likes_metric ||= {name: "Likes", data: object.tweet_metrics.group_by_minute(:created_at).maximum(:likes)} | ||
end | ||
|
||
def replies_metric | ||
@replies_metric ||= {name: "Replies", data: object.tweet_metrics.group_by_minute(:created_at).maximum(:replies)} | ||
end | ||
|
||
def reposts_metric | ||
@reposts_metric ||= {name: "Reposts", data: object.tweet_metrics.group_by_minute(:created_at).maximum(:reposts)} | ||
end | ||
|
||
def bookmarks_metric | ||
@bookmarks_metric ||= {name: "Bookmarks", data: object.tweet_metrics.group_by_minute(:created_at).maximum(:bookmarks)} | ||
end | ||
|
||
def views_metric | ||
@views_metric ||= {name: "Views", data: object.tweet_metrics.group_by_minute(:created_at).maximum(:views)} | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Entry point for the build script in your package.json | ||
import "@hotwired/turbo-rails" | ||
import "./controllers" | ||
import "chartkick/highcharts" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,9 @@ html | |
= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' | ||
= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true | ||
link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css" | ||
script src="https://kit.fontawesome.com/08b1825a15.js" crossorigin="anonymous" | ||
link rel="preconnect" href="https://fonts.googleapis.com" | ||
link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="crossorigin" | ||
link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet" | ||
script src="https://kit.fontawesome.com/08b1825a15.js" crossorigin="anonymous" | ||
body | ||
== yield |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
header.navbar | ||
.container | ||
.navbar-brand | ||
a.navbar-item href="/" | ||
| X-Tracker | ||
span.navbar-burger.burger data-target="navbarMenuHeroA" | ||
span | ||
span | ||
span | ||
.navbar-menu id="navbarMenuHeroA" | ||
.navbar-end | ||
a.navbar-item href="/" | ||
| Home | ||
= link_to "Tweets", tweets_path, class: "navbar-item" | ||
/ a.navbar-item href="/contact" | ||
/ | Contact |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
section.hero.is-info | ||
.hero-head | ||
= render "shared/navbar" | ||
.section | ||
.columns.is-centered | ||
.column.is-1 | ||
h1.rotated.has-text-grey Tracked Tweets | ||
.column.is-10 | ||
- @tweets.each do |tweet| | ||
.card | ||
.card-content | ||
.media | ||
.media-left | ||
figure class="image is-48x48" | ||
img src="#{tweet.author_avatar_url}" class="is-rounded" | ||
.media-content | ||
p class="title is-4" | ||
= link_to tweet.author_name, tweet.author_url, target: "_blank" | ||
p class="subtitle is-6" | ||
= tweet.body.truncate(280) | ||
.content | ||
= tweet.combined_chart | ||
footer.card-footer | ||
= link_to tweet_path(tweet), class: "card-footer-item primary" do | ||
span View Metrics | ||
span.icon | ||
i class="fa fa-chart-line" | ||
= link_to tweet.url, class: "card-footer-item", target: "_blank" do | ||
span View Tweet | ||
span.icon | ||
i class="fa fa-twitter" | ||
.column.is-1 |
Oops, something went wrong.