Giter Club home page Giter Club logo

twendy's Introduction

Twendy

By Lior Elrom.

####http://twendy-app.herokuapp.com


Twendy is a visual application that presents global Twitter trends in the past 24 hours.

Twendy

Background

Twitter users send more than 95 million Tweets a day, on just about every topic imaginable. This is quite a lot to handle! In order to better understand what are the most popular topics people are tweeting about, Twitter decided to track the volume of terms mentioned by its users on an ongoing basis and turn them into topics. When the volume of tweets about a given topic dramatically increases at a given moment, a Trend is born!

Since Twitter Trends represent topics that are being talked about more right now than they were previously, we decided it would be a great idea to feel the world's pulse by building an application that will give a visual and easy access to those trends and track their popularity at any given time.

We choose to serve this data on a globe, divided into countries, where clicking on a specific country will bring-up its 10 most recent trends and present how they were changing in the past 24 hours. Twitter currently tracks 63 countries but we plan on growing along when Twitter as it adds more countries to it's list.

How to use Twendy?

Drag the globe to your desired country and click it! A pop-up window will come up with the country's 10 hottest trends and their rate of appearance in the past 24 hours. The trend's popularity is being represented by a heat-map table where the hottest trend has a red color and the least with blue.

When you want to return to the whole globe country, just click the last country you clicked before (as it marked with an orange color).

Twendy

Technologies

  • Ruby on Rails 4
  • PostgreSQL
  • Heroku Task Scheduler
  • Javascript
  • jQuery
  • AJAX
  • d3.js
  • API's (Twitter, Yahoo WOEID and Geocoder)
  • rspec

Code and Stracture

Twendy is combind from 3 models:

  • Country: holding the country information including the timestamp of when its trends was last updated.
  • Trend: holding each and every uniq trend information
  • CountriesTrend: using as a join table by assigning each trend to its country (or countries)

All the code, throughout the application, is well commented for readability and future debugging.

def self.process_data(data, trend_id, index)
	result = []
	interval = 2 # check trend every 2 hours
	time = Time.now
	cycle = 60 * 60 * 2 # two hours cycle
	my_trend = Trend.find(trend_id)

	until interval > 24 do
		# get all trends for that time cycle
		trends = data.map {|record| record if record[:time_of_trend] <= time && record[:time_of_trend] > (time - cycle) }.compact

		# get all ranks for those trends
		ranks = trends.map {|trend| trend[:rank] }.compact
		ranks = [0,0] if ranks.empty?

		# calculate an avarage rank and round or floor the result
		# floor when last rank is better and round vise versa
		median = ranks.inject { |sum, rank| sum + rank }.to_f / ranks.length
		avarage_rank = (ranks.length == 1) ? median.floor : (ranks[0] < ranks[1]) ? median.floor : median.round

		# build the dataset that will match the heat map requirments
		result << { :"name" => my_trend.name, :"twitter_url" => my_trend.twitter_url, :"interval" => interval, :"trend" => index, :"rank" => avarage_rank }

		time -= cycle # set time as 2 hours before
		interval += 2 # next interval
	end
	result
end

And also scalable and devided to different templates

<%= render "layouts/templates/globe" %>

<%= render "layouts/templates/drawer" %>

<%= render "layouts/templates/heatmap" %>

##Test Driven Development

I am a big fan of testing and strongly believe that every application should contain testing units in order to improve existing code and maintain a working application. As a result, Twendy is well tested on the server side with 100% covarage.

TDD

twendy's People

Contributors

liormb avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.