228 lines
12 KiB
HTML
228 lines
12 KiB
HTML
<head>
|
|
<title>Evan Pratten</title>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
|
|
|
<!-- Begin Jekyll SEO tag v2.6.1 -->
|
|
<title>Graphing the relation between wheels and awards for FRC | Evan Pratten</title>
|
|
<meta name="generator" content="Jekyll v4.0.0" />
|
|
<meta property="og:title" content="Graphing the relation between wheels and awards for FRC" />
|
|
<meta property="og:locale" content="en_US" />
|
|
<meta name="description" content="AKA. Why programmer + reddit + matplotlib is a bad idea." />
|
|
<meta property="og:description" content="AKA. Why programmer + reddit + matplotlib is a bad idea." />
|
|
<link rel="canonical" href="http://0.0.0.0:4000/blog/2019/06/16/graphing-w2a" />
|
|
<meta property="og:url" content="http://0.0.0.0:4000/blog/2019/06/16/graphing-w2a" />
|
|
<meta property="og:site_name" content="Evan Pratten" />
|
|
<meta property="og:type" content="article" />
|
|
<meta property="article:published_time" content="2019-06-16T11:51:00-04:00" />
|
|
<script type="application/ld+json">
|
|
{"datePublished":"2019-06-16T11:51:00-04:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://0.0.0.0:4000/blog/2019/06/16/graphing-w2a"},"@type":"BlogPosting","url":"http://0.0.0.0:4000/blog/2019/06/16/graphing-w2a","headline":"Graphing the relation between wheels and awards for FRC","description":"AKA. Why programmer + reddit + matplotlib is a bad idea.","dateModified":"2019-06-16T11:51:00-04:00","@context":"https://schema.org"}</script>
|
|
<!-- End Jekyll SEO tag -->
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
|
|
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="/assets/css/main.css">
|
|
<link rel="stylesheet" href="/assets/css/github-syntax.css">
|
|
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono:400,400i|IBM+Plex+Sans:100,100i,400,400i,700,700i" rel="stylesheet">
|
|
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="site-ctr">
|
|
<!-- Navbar -->
|
|
<nav class="navbar navbar-dark sticky-top bg-dark navbar-expand-lg">
|
|
<!-- Navbar content -->
|
|
<!-- <div class="container"> -->
|
|
<a class="navbar-brand" href="/">Evan Pratten</a>
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup"
|
|
aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
|
<div class="navbar-nav ml-auto">
|
|
<a class="nav-item nav-link" href="/blog">Blog</a>
|
|
<a class="nav-item nav-link" href="/projects">Projects</a>
|
|
<!-- <a class="nav-item nav-link" href="/documentation">Documentation</a> -->
|
|
<a class="nav-item nav-link" href="/about">About</a>
|
|
</div>
|
|
<!-- </div> -->
|
|
</div>
|
|
</nav>
|
|
<!-- <div style="height:5vh"></div> -->
|
|
|
|
<!-- Header -->
|
|
<!-- <div class="header">
|
|
<div class="container">
|
|
<div class="content">
|
|
</div>
|
|
</div>
|
|
<div class="header-gap"></div>
|
|
</div> -->
|
|
|
|
<div class="reactive-bg">
|
|
<div class="post container">
|
|
<h1>Graphing the relation between wheels and awards for FRC
|
|
|
|
</h1>
|
|
<h4>AKA. Why programmer + reddit + matplotlib is a bad idea.
|
|
|
|
</h4>
|
|
<hr>
|
|
<p><em>2019-06-16 11:51:00 -0400
|
|
|
|
</em></p>
|
|
|
|
<br>
|
|
|
|
<p>I was scrolling through reddit the other day, and came across <a href="https://www.reddit.com/r/FRC/comments/byzv5q/i_know_what_im_doing/">this great post</a> by u/<a href="https://www.reddit.com/user/MasterQuacks/">MasterQuacks</a>.</p>
|
|
|
|
<p><img src="/assets/images/w2ainspo.jpg" alt="My insporation" /></p>
|
|
|
|
<p>I thought to myself “ha. Thats funny”, and moved on. But that thought had stuck with me.</p>
|
|
|
|
<p>So here I am, bored on a sunday afternoon, staring at the matplotlib documentation.</p>
|
|
|
|
<h2 id="my-creation">My creation</h2>
|
|
<p>In only a few lines of python, I have a program that will (badly) graph the number of awards per wheel for any team, or set of teams.</p>
|
|
|
|
<p>As always, feel free to tinker with the code. This one is not published anywhere, so if you want to share it, I would appreciate a mention.</p>
|
|
|
|
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">requests</span>
|
|
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="n">plt</span>
|
|
|
|
<span class="k">class</span> <span class="nc">Team</span><span class="p">:</span>
|
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">wheels</span><span class="p">):</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="nb">id</span> <span class="o">=</span> <span class="nb">id</span>
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">wheels</span> <span class="o">=</span> <span class="n">wheels</span> <span class="o">*</span> <span class="mi">2</span>
|
|
|
|
<span class="c1">### CONFIG ###
|
|
</span>
|
|
<span class="n">teams</span> <span class="o">=</span> <span class="p">[</span><span class="n">Team</span><span class="p">(</span><span class="mi">5024</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">Team</span><span class="p">(</span><span class="mi">254</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="n">Team</span><span class="p">(</span><span class="mi">1114</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">Team</span><span class="p">(</span><span class="mi">5406</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span> <span class="n">Team</span><span class="p">(</span><span class="mi">2056</span><span class="p">,</span> <span class="mi">4</span><span class="p">)]</span>
|
|
<span class="n">year</span> <span class="o">=</span> <span class="mi">2019</span>
|
|
|
|
<span class="c1">##############
|
|
</span>
|
|
|
|
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">team</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">teams</span><span class="p">):</span>
|
|
<span class="n">award_data</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"https://www.thebluealliance.com/api/v3/team/frc"</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">team</span><span class="o">.</span><span class="nb">id</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/awards/"</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">year</span><span class="p">),</span> <span class="n">params</span><span class="o">=</span><span class="p">{</span><span class="s">"X-TBA-Auth-Key"</span><span class="p">:</span> <span class="s">"mz0VWTNtXTDV8NNOz3dYg9fHOZw8UYek270gynLQ4v9veaaUJEPvJFCZRmte7AUN"</span><span class="p">})</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
|
|
|
|
<span class="n">awards_count</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">award_data</span><span class="p">)</span>
|
|
|
|
<span class="n">team</span><span class="o">.</span><span class="n">w2a</span> <span class="o">=</span> <span class="n">awards_count</span> <span class="o">/</span> <span class="n">team</span><span class="o">.</span><span class="n">wheels</span>
|
|
<span class="k">print</span><span class="p">(</span><span class="n">team</span><span class="o">.</span><span class="nb">id</span><span class="p">,</span> <span class="n">team</span><span class="o">.</span><span class="n">w2a</span><span class="p">)</span>
|
|
|
|
<span class="n">plt</span><span class="o">.</span><span class="n">bar</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">team</span><span class="o">.</span><span class="n">w2a</span><span class="p">,</span> <span class="n">tick_label</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">team</span><span class="o">.</span><span class="nb">id</span><span class="p">))</span>
|
|
|
|
<span class="c1"># Plot
|
|
</span><span class="n">x_lables</span> <span class="o">=</span> <span class="p">[</span><span class="n">team</span><span class="o">.</span><span class="nb">id</span> <span class="k">for</span> <span class="n">team</span> <span class="ow">in</span> <span class="n">teams</span><span class="p">]</span>
|
|
<span class="c1"># plt.set_xticklabels(x_lables)
|
|
</span>
|
|
<span class="k">with</span> <span class="n">plt</span><span class="o">.</span><span class="n">xkcd</span><span class="p">():</span>
|
|
<span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">'Awards per wheel'</span><span class="p">)</span>
|
|
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
|
|
|
|
</code></pre></div></div>
|
|
|
|
<h2 id="the-result">The result</h2>
|
|
<p>Here is the resulting image. From left, to right: 5024, 254, 1114, 5406, 2056</p>
|
|
|
|
<p><img src="/assets/images/w2a.png" alt="Thr result" /></p>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<!-- <div id="particles-js"></div> -->
|
|
|
|
<div class="container foot" style="text-align:center;">
|
|
<br>
|
|
<span class="site-info">
|
|
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
|
|
|
|
This site was last updated at: 2019-11-30 11:37:59 -0500
|
|
</span>
|
|
</div>
|
|
|
|
<!-- Brython -->
|
|
<script src="/assets/js/brython.js"></script>
|
|
<script src="/assets/js/brython_stdlib.js"></script>
|
|
|
|
<script>
|
|
function startPY(){
|
|
|
|
brython();
|
|
console.log("Started Python")
|
|
}
|
|
|
|
window.onload = startPY;
|
|
</script>
|
|
|
|
|
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
|
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
|
crossorigin="anonymous"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
|
|
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
|
|
crossorigin="anonymous"></script>
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
|
|
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
|
crossorigin="anonymous"></script>
|
|
|
|
<!-- Offsets for links -->
|
|
<script>
|
|
(function ($, window) {
|
|
var adjustAnchor = function () {
|
|
|
|
var $anchor = $(':target'),
|
|
fixedElementHeight = 100;
|
|
|
|
if ($anchor.length > 0) {
|
|
|
|
window.scrollTo(0, $anchor.offset().top - fixedElementHeight);
|
|
}
|
|
|
|
};
|
|
|
|
$(window).on('hashchange load', function () {
|
|
adjustAnchor();
|
|
});
|
|
|
|
})(jQuery, window);
|
|
</script>
|
|
|
|
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-74118570-2"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag() { dataLayer.push(arguments); }
|
|
gtag('js', new Date());
|
|
|
|
gtag('config', 'UA-74118570-2');
|
|
</script>
|
|
|
|
|
|
<!-- particles -->
|
|
<script>
|
|
var body = document.body
|
|
|
|
var particles = document.getElementById("particles-js")
|
|
|
|
particles.style.height = body.scrollHeight + "px"
|
|
|
|
console.log(body.scrollHeight)
|
|
</script>
|
|
<script src="/assets/js/particles.min.js"></script>
|
|
<script>
|
|
particlesJS.load('particles-js', '/assets/js/particles.json', function () {
|
|
console.log('callback - particles.js config loaded');
|
|
});
|
|
</script>
|
|
|
|
<!-- Twitter embeds -->
|
|
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
|
|
|
|
|
|
</body> |