Wednesday, January 20, 2016

Desk Cycle Bike Race

A buddy of mine at work purchased a Fit Desk Under desk Elliptical trainer. You may recall another buddy of mine (Chad Bisher) has one and uses it to illegally win FitiBit Workweek Hustle challenges. Anyway, intrigued I wanted to try it out when it arrived.



I immediately determined this is something I'd like to purchase. As luck would have it Chad Bisher's wife, the doc, had purchased a Desk Cycle but rarely used it and was willing to sell it to me.



I quickly installed it and got it adjusted to my work area and started pedaling. Of course in true thejoestory fashion I was not satisfied with merely riding the bike and receiving the health benefits. I quickly challenged my co-worker to a competition. A virtual bike race to various destinations in the world. We will see who can pedal the farthest, the fastest, etc.

Website


Thus the Bikerace website was born.


Our first destination was Chicago from our HQ here in Kansas City. I am not sure why or how I picked Chicago. Anyway we started tracking metrics: Miles, Time, Calories burned. Progress to the goal was displayed on the site.


I decided to use the bootstrap framework for this site. I have been using foundation a lot and wanted to change things up a bit. Bootstrap has a lot of features to offer. We will see how it goes.

One thing we noticed right away was the difference in speed calculations between the two bikes. The FitDesk seems to measure speed differently. My co-workers speed was registering 5 MPH faster than the Desk Cycle.

We both tried the other person's cycle and the results were similar. Therefore I will add a modifier to my buddy's distance. As you can see in the screenshot...I have ridden over 2 hours more than him and I am only 9 miles ahead of him to Chicago.

Anyway I will tweak the numbers and see how it goes.

Future Plans


I would like to pinpoint where we each rider is located along the route based on miles. I have not figured out how to do that on Google Maps yet. I need to figure out how to do Lat/Long math along a path given a specific bearing. Should be an interesting challenge.

Other than that we just have to come up with where we want to ride next. By the time the Tour de France rolls around we may mimic some of the legs by cranking up the resistance on the bike for the mountain climbs and such. Yes I know it is nothing like the real tour...just something fun to try.




Monday, January 4, 2016

Monday, December 28, 2015

Twitter Sentiment with Python Part 2

Earlier I blogged about grabbing some tweets from Twitter and running them through a text sentiment analysis module using Python. I recently revisited the project and added a new feature.

Here is the full script. Below I will add some notes



Some Notes


So I setup the script to run every 15 minutes against the keyword Kansas City to track the sentiment of this fine Midwestern town in the Great USA. I turned the script lose and sorta forgot about it for  month or so.

Kansas City is not the most polarizing of search terms on Twitter. Out of the 5000+ executions of the script the sentiment went negative a total of 88 times (1.76%).  The top 10 negative sentiment scores were recorded at the times in the table below.


Negativecapturedate
0.99999574912/6/15 15:38
0.99995177112/20/15 13:52
0.99989486212/16/15 15:53
0.99985036511/29/15 14:52
0.99981270612/25/15 8:52
0.99942610912/20/15 12:22
0.99942192512/17/15 22:22
0.99894590212/6/15 14:23
0.99340058711/18/15 16:52
0.99275798512/13/15 15:53


  • Odd that I did not see any negative sentiment hits on Thanksgiving.  Black Friday did not even have a hit.
  • 12/25/2015 @ 8:52AM apparently some folks did not like their Christmas gifts in Kansas City.
  • 12/20/2015 from 12:07 - 21:07. This time span had the most negative sentiment hits of the entire data set. A quick search on twitter for that day did not yield any clues. I also searched the news outlets and did not see anything obvious.
After reviewing the collected data I noticed a problem with my process. I am parsing the tweets to score the sentiment, however I cannot go back to review the tweets to see what caused the sentiment. 

Therefore I launched version 2 of the script (the script listed above) and added a new table to my database. I am now capturing the actual tweets as well as storing the sentiment score. I changed the capture time to 30 minutes.

Website


During the initial script build I also wanted a way to visualize the current sentiment in a sort of heat map type color system based on the negative score. I remember searching a while for this code but now I cannot remember where I found it. Anyway basically it will set the background color of this web page based on the value of the negative score. The negative score is determined using the sentiment analyzer.

If the negative score is close to 0 then the page will be green. If the negative score is close to 1 then the page will be red. If the negative score is .5 the page will be blue. Everything in between will be a various shade of these 3 main colors. Here is a sample of a high negative sentiment, the numbers are off here because I hijacked the code to negative sentiment of 1 to show the red color.:


All of this is driven by the code below.


So there you have it. I have cranked up the script again to collect data every 30 minutes. I predict in about a month or so I will remember that the script is running and will blog the findings. One of the next steps I want to do is incorporate the values in the D3js calendar chart. However, I may have to pick a more polarizing topic otherwise the whole year will be green.




Thursday, December 24, 2015

Fusion Table API Insert Data Python

Me and a buddy have been hacking at this Google Fusion API for a couple days now trying to figure it out. We finally had a break through. He sent me his sample code with the authentication piece and the SELECT statement and I started trying an INSERT. After about 10 rounds of fail finally got something to work and wanted to post it. We struggled to find a simple sample on how to do this, I am sure there is a better way, but at least its working.

Python Modules Needed


You will need to install some Python modules if you have not authenticated to the Google APIs before. Here is a list of modules I installed. 

  • requests
  • urllib3
  • apiclient
  • gspread
  • PyOpenSSL
  • oauth2client
  • google-api-python-client (used easy_install)
Not all of these are needed for the script. I am working from a new laptop so I had install them fresh. All of these were installed using pip except the Google API Python client. For some reason pip did not install that so we had to use easy_install.


Authentication


We used the same method detailed in this earlier post using the gspread module. You will want to create the JSON file with your authentication key in it so you can authenticate to the Fusion Table API.

Make sure you grant your client email address access to edit the Fusion table. You can do this using the Fusion Table Share feature and then add the email from the JSON file you downloaded when  you built your key   XXXXXXXXXXXXXXX@developer.gserviceaccount.com



Script


I am using the USGS Earthquake JSON feed I blogged about earlier today to import Earthquake data in to a Fusion Table. Here is the script.


Basically we just setup a loop to parse the Earthquake JSON data and on each loop we execute an INSERT statement in Fusion. Again there is probably a better way than the line by line method detailed here. But again at least we can import data into Fusion. This is not going to be practical for thousands of rows but is fine for our purpose here.

Earthquake Data JSON feed

Previously on the blog I consumed earthquake data from a CSV produced by the USGS website. Recently I revisited the USGS website and worked on consuming their JSON feed.

You can find information on their feed here: http://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php

I am as giddy as a 11 year old girl at a One Direction concert when I see a website has a JSON feed. Here is the python script I used to consume the data and create the text file to import.



From there I was able to import the data into Google Fusion Tables. I tried using the Fusion Table API to knock this out automagically, but did not have much luck. Plan to keep hacking at the Fusion Table API to see what I can come up with.  In the meantime here is a map of all the Earthquakes that occurred 12/23/2015







Here is a link to the full screen map:
https://www.google.com/fusiontables/embedviz?q=select+col4+from+1aXGZQoukkHHSAKSHuCakYuVbh2qSaBxN5C-APpOE&viz=MAP&h=false&lat=9.66632685018197&lng=1.11668359374994&t=1&z=2&l=col4&y=2&tmplt=2&hml=TWO_COL_LAT_LNG




Wednesday, December 23, 2015

Link Dump 12/23/2015

Trying to start a semi frequent blog post with links, hand curated links about stuff I find. More for me than you.


Monday, November 2, 2015

Candy Tracker 2016








Round 2 of the Candy Tracker. I was able to get a few more candy loggers this year as we embarked on another Halloween Candy Haul. The SweetSpots map was on hot with candy logging action. Let's see how the night unfolded.





First Stop TLC


TLC kicks the night off from 3PM-5PM.  a great way to get a candy score before dinner. It is the earliest event around our town so of course it makes sense to hit it first and hit it hard. My boy Luke threw such a fit getting his Thor costume on (refused to take a nap) that we didnt realize he wasn't wearing shoes when we got to TLC. Oh well, we are not going to let a couple sore 4 year old feet slow us down on our first score (it is a short walk don't hot line me).


You can guarnetee you are going to get some "Gimmicky Garbage" here at the TLC Trunk or treat. We were not let down.  A small box of tissues, a first aid kit (pretty cool on any other night), and some new frisbees (to add to the 2 from last year). They also had a ring toss and a bean bag game where you got to pick out some trinkets from the bucket. The Kleenex box rated right up there with the Twizzlers at a 3/10. The only other red score here was the dreaded Almond Joy. Coop actually made an attempt to eat an Almond Joy, he knew the error of his ways about .2 seconds in. 

Second Stop the Square


Second stop of the night was the Liberty Square. We had to book it back home to get Luke some shoes for this haul. This one involved a little more walking. This event is from 5PM-7PM. Again another great way to score a ton of candy in a small area. As an added double bonus there is also a great Trunk or Treat just 1 block from the square as you can see on the SweetSpots map.


The Liberty Square is what we call a pure candy score. Businesses can't afford to let the kids down here, so they hand out candy. We had 1 red pin here but it was actually a combo score of Gimmicky Garbage and candy. The Gimmicky Garbage was a stress ball which was involved later in the night in a brother on brother battle royal where said stress balls were taken away.

The Trunk or Treat off the square is a decent spot for candy. It has a great candy to distance walked ratio. However as you can see there are a couple folks who haven't read the rules of proper candy dispersion. Some poor lady was trying to give out Colgate toothpaste. I was so proud of my little Thor when he just flat refused to take the toothpaste and walked past her.

Last Stop Grandma's


We made a final stop, after hitting Chipolte for 3$ burritos, at Grandma's neighborhood. This is more of a tradition then a good strategy for maximizing our candy score. Grandma's street does have a lot of houses that participate so it's not a terrible score. Usually by this time I am pretty much Halloween-ed out. That and we were wanting to catch Game 4 of the World Series to cheer on our Royals.


I logged a few pieces and we called it a night.

Friends of thejoestory


As I mentioned I had a few more people log candy this year. My Gladstone friends were logging crazy. Look at all those pins.




A quick review of the data and I did not find any green pins. Man what gives. So I started looking more closely. 



PB cups a 7? Milky Way a 6? Twix a 6? Kit Kat a 6? Tough candy crowd out at Gladstone. They are not totally crazy because Swedish Fish and Nerds were properly rated at a 2 and 3. Team Gladstone did not rate a single piece of candy higher than a 7. Wonder what Gladstone folks think is a 8,9 or 10 piece of candy.


We had a few other pieces logged throughout the metro. 




Counts


All and all not a bad candy haul this year. We had Thor and a Jedi so we doubled up on Candy. We are sending a large bag up to school with Coop to give to the Troops. Thanks for all who logged candy. Here are the counts.

  • 126 total pieces logged. 
  • Heath bar gets an unfair advantage cause it is one of my favorites. 
  • Snickers and Kit Kat were among the most popular. 
  • Healthy at a 4 was the toothpaste...seems a little high but I was rating on utility.

AvgRatingCountCandycandy
81Heath Bar
7.333Hershey Bar
73Crunch Bar
6.52Butterfinger
6.52Laffy Taffy
6.4511Kit Kat
6.4212Snickers
6.388Tootsie Roll
6.254Reeses PB Cups
62Milk Duds
63Milky Way
62Popcorn
63Whoppers
5.8363 Muskateers
5.85Twix
5.638Sucker
5.410Skittles
52Smarties
58Starburst
51Sweet Tarts
4.9212Other
41Healthy
42Twizzlers
3.52Almond Joy
3.52Tootsie Roll Pop
3.297Gimmicky Garbage
31Jolly Rancher
31Nerds
21Pretzels
21Swedish Fish


Sunday, October 25, 2015

The Legend of Chad Bisher


step
/step/
noun

an act or movement of putting one leg in front of the other in walking or running


Seems simple enough. Straight forward definition. But my buddy Chad Bisher challenged this definition and taught us all to reach for our dreams and follow our hearts this week.

It all started with a friendly Fitbit Work Week Step count challenge thrown down by none other than thejoestory. I invited a few Fitbit friends to step up to the challenge in what I am now labeling "THE Hot Stepper October Work Week Challenge of 2015, Murderer".

I knew something was a miss Early Tuesday of the competition. Chad Bisher had a big lead (like a whole day's worth of steps lead) by Tuesday Morning. I quickly rememberd what gave Chad Bisher the early week edge.

Chad Bisher owns a desk cycle. For the uninformed, the desk cycle is a small bicycle apparatus you can fit under your desk that allows you to pedal while you are sitting at your desk. Chad Bisher was racking up thousands and thousands of steps on the desk cycle.

Taken a back by this brazen display of competitive advantage I decided to email some folks for an impartial opinion. The problem, in my opinion, was that a step counted on a desk cycle is not truly a step. You are not supporting your full body weight and you are not moving from your current position.

Emails started flooding in, and quickly two teams formed.

FREE CHAD BISHER






Some crazy folks were actually in support of Chad Bisher.

"hahahahahaha" was one response which I counted as a support for Bisher.

"So have you ever tried so called deskcycle? What's preventing you from doing the same thing?"

"If seated cycling was allowed it should have been clear to all competitors"

"Would you count steps any differently if he was riding a stationary bike...if you would then you count the deskcycle steps too"

Some supporters went as far as printing up some tshirts for the FREE BISHER CAUSE.



CHAD BISHER RUNS SCAMS



The other side of the argument, the more sane people, had this to say.

"I am sure he is a nice guy and all but it also seems like he is a pumpkin eater (cheater cheater)"

"In my world there are many kinds of steps, but they all requires two components... moving ones lower extremity forward (even 0.01 inches), AND transferring standing body weight to that extremity. So I would say that he is not taking a step by pedaling a bike in a non weight-bearing position, as one cannot sit and walk simultaneously. Id have a hard time coming up with a formula to translate pedaling a bike to walking, too many variables. Walking and pedaling use a few of the same leg muscles, but it would be like comparing casually throwing a ball 100 times to doing 100 push-ups. Similar arm and shoulder muscles used, but too many variables to compare. If it was a competition of STEPS, I would say he knowingly racked up thousands of "steps" on his pedometer without leaving his seat, and should either subtract the approximate number of revolutions he made on he bike from his score, or be disqualified from he competition."

"While it seems that the majority of the competitors are all within "steps" reach of one another, Chad is walking away by 20k plus. I feel that this is similar to the Barry Bonds doping scandal with home runs. Rumor has it that steps are being calculated with the Fitbit attached somewhere other than the proper wrist location. I feel there needs to be an investigation launched by federal authorities into this scandal. "

"I don't have a Fitbit so I don't feel like I should get a say. Since you asked though, it's cheating for sure. Punish him!"

"I think the CBDBCC should be set to whatever value makes his total steps lower than yours.  Is that impartial enough for you?'
I agree that Chad has an advantage that does not permit a level playing field.

Adjustments Needed


So after the crowd weighed in...where do we stand? I think we have to do a step adjustment. I proposed a very straight forward calculation for adjustment.


  • Legs account for 16.88% of the average Male Body weight
  • Add a multiplier for unknown resistance setting of the bike
  • Multiply Chad Bisher's steps by .328
  • Add 10000 steps back to his total to account for non bike steps


From here you arrive at the adjusted step count for Chad Bisher. Then we see where he stands in the leader board. If he is still ahead of me then we subtract off just enough steps so the calculation still looks legit while allowing me to maintain the step total victory. Seems simple enough.

Battle to the End


So for all intents and purposes Chad Bisher was out of the competition. So it ended up being a battle between me and the Doc. Friday I ran to The Scout and back which is around 4.75 miles. Doc hit the gym after work and straight owned it.

I was down by about 5000 steps when I got home. The Royals started Game 6 of the ALCS at 7:00PM. By 8:10PM I convinced myself that I must defeat the Doc. So I embarked on another 4 mile run.


I get back from the run and realize I am still 1200 steps behind. The Doc is on the move, the Royals game is a nail biter, and we only have about 3 more hours to go on this competition.

I would sync, up 300 steps, the Doc would sync down 412 steps. We are both pacing and walking at this point in a fight to the finish. The ALCS game had a 45 minute rain delay and the Doc made the mistake of taking a breather during the rain delay. I never stopped walking from 9:00PM - 12:00AM and finished up a couple thousand steps on the Doc.

I earned the 35K step badge. It took 8.5 miles of running and 3 hours of constant walking but somehow I managed to edge past the Doc.





Results


The step contest ended 10/23/2015 @ 11:59:59PM. Here are the final results: Adjusted and non-adjusted.

Non-Adjusted

Hot StepperSteps
Chad Bisher115375
thejoestory105036
Doc102577
Wild Man David64380
The Professor52821
Brown Bear47335
Major H35160

Adjusted
I ended up multiplying Chad Bisher's steps by .582 which, to me, factors in resistance settings and other steps taken throughout the week. Remember this is me coming up with some arbitrary metric to ensure my victory.



Hot StepperSteps
thejoestory105036
Doc102577
Chad Bisher67148
Wild Man David64380
The Professor52821
Brown Bear47335
Major H35160

Tuesday, September 22, 2015

CentOS Sox playing MP3 from Command Line

I simply wanted to play a MP3 from the command line as project 2 of the Amazon Dash Button hack. This took me way longer than I wanted so I thought I would put the instructions here. SoX is a utility that was installed with my CentOS out of the box, however it would not play MP3s by defualt.

I tried installing LAME using standard repos but that is apparently not going to happen. I finally found some like with RPMFusion.


  1. Install RPMFusion
  2. Remove Sox
  3. Install the necesssary libraries and such for Lame
  4. Make a local directory fo SoX
  5. Get SoX using wget from sourceforge.
  6. Extract Sox
  7. Run configure
  8. You should see lame in the list from the configure output
  9. Run a make
  10. Run make install

From here run the sox from the command line and MP3 should be in the list of supported files.
To play a file simply run sox and pass it a file name



Update


Well SoX didnt really work for me. I was able to have some luck with VLC though. In order to install VLC you need to add the Desktop Repos.

http://li.nux.ro/repos.html

Execute this command to install the desktop repos


Then from there you can run VLC like so