<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rit-2171</title><link>https://jwheel.org/tags/rit-2171/</link><description>Homepage of Justin Wheeler, an Open Source contributor and Free Software advocate from Georgia, USA.</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><managingEditor>Justin Wheeler</managingEditor><lastBuildDate>Mon, 18 Dec 2017 00:00:00 +0000</lastBuildDate><atom:link href="https://jwheel.org/rss/tags/rit-2171/index.xml" rel="self" type="application/rss+xml"/><item><title>Statistics proposal and self-hosting ListenBrainz</title><link>https://jwheel.org/blog/2017/12/statistics-hosting-listenbrainz/</link><pubDate>Mon, 18 Dec 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/12/statistics-hosting-listenbrainz/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>This week is the last week of the fall 2017 semester at RIT. This semester, I spent time with the MetaBrainz community working on ListenBrainz for an independent study. This post explains what I was working on in the last month and reflects back on my <a href="/blog/2017/10/contributing-listenbrainz/">original objectives</a> for the independent study.</p>

<h2 id="running-my-own-listenbrainz">Running my own ListenBrainz&nbsp;<a class="hanchor" href="#running-my-own-listenbrainz" aria-label="Anchor link for: Running my own ListenBrainz">🔗</a></h2>
<p>The <a href="http://ritlug.com/">RIT Linux Users Group</a> hosts various virtual machines for our projects. I requested one to set up and host a &ldquo;production&rdquo; ListenBrainz site. The purpose of doing this was to…</p>
<ol>
<li>Test my changes in a &ldquo;production&rdquo; environment</li>
<li>Offer a service for the RIT Linux Users Group to poke around with</li>
</ol>
<p>I spent most of this time working with our system administrator to set up the machine and adjust hardware specs for ListenBrainz. Once we fixed storage space and memory issues, it was easy to set it up and get ListenBrainz running. My experience writing the <a href="https://listenbrainz.readthedocs.io/en/latest/dev/devel-env.html">development guide</a> made it easy to get set up and get working. On the first run, it worked!</p>
<p>Now, <a href="http://listen.ritlug.com/">listen.ritlug.com</a> is live.</p>

<h4 id="figuring-out-https">Figuring out HTTPS&nbsp;<a class="hanchor" href="#figuring-out-https" aria-label="Anchor link for: Figuring out HTTPS">🔗</a></h4>
<p>My next challenge for the site is to set up HTTPS. I tried using a <a href="https://www.nginx.com/resources/admin-guide/nginx-https-upstreams/">reverse proxy in nginx</a> to set up HTTPS, but I received <em>502 Bad Gateway</em> errors. I realized I spent too much time figuring this out on my own and decided to <a href="https://community.metabrainz.org/t/how-does-metabrainz-use-https-on-listenbrainz/347319">ask for help</a> in the MetaBrainz community forums.</p>

<h2 id="proposing-new-statistics">Proposing new statistics&nbsp;<a class="hanchor" href="#proposing-new-statistics" aria-label="Anchor link for: Proposing new statistics">🔗</a></h2>
<p>Halfway through the independent study, I realized I would fall short of my original objective of implementing basic statistics in ListenBrainz. To compromise, I wrote a <a href="https://docs.google.com/document/d/1kByAgC9kbuDHNbsEJDkYkTMJ-wAoouWj0qNyi2UPb2Y/edit?usp=sharing">proposal for new statistics</a> to start in the project. My proposal looked at other proprietary platforms that compete with ListenBrainz to see some of their statistics. I also came up with some of my own.</p>
<p>I <a href="https://community.metabrainz.org/t/feedback-needed-listenbrainz-statistics-proposal/347327">proposed this to the MetaBrainz community</a> on the community forums. I&rsquo;m awaiting feedback on my ideas. Once I get feedback, I plan to file new tickets for each statistic to track their implementation over time.</p>
<p>I don&rsquo;t expect statistics being at the forefront of ListenBrainz for some time. A lot of work is going towards other areas of the project. But later in 2018, I expect more focus on the user-facing side of the project.</p>

<h2 id="my-statistic-and-google-bigquery">My statistic and Google BigQuery&nbsp;<a class="hanchor" href="#my-statistic-and-google-bigquery" aria-label="Anchor link for: My statistic and Google BigQuery">🔗</a></h2>
<p>My biggest blocker over the last month was <a href="https://cloud.google.com/bigquery/">Google BigQuery</a>. I wrote a statistic to <a href="https://github.com/metabrainz/listenbrainz-server/pull/318/commits/c1c08ce7f8d207591daeb288087872616d5063a4">calculate play counts</a> over a time period, but was asked to test my statistic. To test my statistic, I needed real data to work with.</p>
<p>Originally, I tried using the <a href="https://github.com/tgwizard/sls">Simple Last.fm Scrobbler</a> to submit listens to the local IP address for my development environment, but I wasn&rsquo;t able to get the app to reach my ListenBrainz server. To get the data, I had to set up Google BigQuery credentials so I could make queries against data on the production site, <a href="https://listenbrainz.org/">listenbrainz.org</a>.</p>
<p>I tried working through the <a href="https://cloud.google.com/bigquery/docs/">Google BigQuery documentation</a>. There&rsquo;s a lot of documentation for using BigQuery as a developer, but it was confusing where to find the information I needed to set it up in my development environment. I tried creating a new project in the Google Cloud Platform, but I was confused because it prompted me to upload my own data instead of accessing data already in BigQuery.</p>
<p>Too late, I realized I spent too much time on my own and not asking for help. I <a href="https://github.com/metabrainz/listenbrainz-server/pull/318">submitted a pull request</a> with the statistic I made and <a href="https://community.metabrainz.org/t/how-to-set-up-google-bigquery-in-a-listenbrainz-development-environment/347307">asked for help</a> in the MetaBrainz community. I also offered to write documentation for setting this up once I learn how to do it.</p>

<h2 id="reflecting-back">Reflecting back&nbsp;<a class="hanchor" href="#reflecting-back" aria-label="Anchor link for: Reflecting back">🔗</a></h2>
<p>I looked back on my <a href="/blog/2017/10/contributing-listenbrainz/">original objectives</a> for the independent study, and I was satisfied and dissatisfied.</p>

<h4 id="not-enough-programming">Not enough programming&nbsp;<a class="hanchor" href="#not-enough-programming" aria-label="Anchor link for: Not enough programming">🔗</a></h4>
<p>I wanted this independent study to enhance my programming knowledge. I especially wanted to focus on Python because I wanted to become more familiar with the language. However, I actually didn&rsquo;t do much programming during the independent study, to my own fault.</p>
<p>My biggest challenge was I bit off more than I could chew. I wanted to write code, and made a big goal before I knew the code base of the project. Even now, I still am not completely comfortable with the code yet. It&rsquo;s a big project with a lot of things going on. I was able to understand the things I did work on, but there&rsquo;s still a lot.</p>
<p>I realized that next time, I need to spend more time evaluating the code base of a project before writing out my milestones. I wish I set more realistic, smaller milestones for myself. My milestone of implementing basic reports was lofty given my existing programming knowledge.</p>

<h4 id="successes">Successes&nbsp;<a class="hanchor" href="#successes" aria-label="Anchor link for: Successes">🔗</a></h4>
<p>One of my other objectives was to write documentation for the project. I felt I succeeded in this milestone, and actually found it enjoyable and interesting to do! I helped separate out documentation from the README into the dedicated <a href="https://listenbrainz.readthedocs.io/en/latest/">ReadTheDocs site</a>. I wrote the <a href="https://listenbrainz.readthedocs.io/en/latest/dev/devel-env.html">development environment guide</a> and helped fix some build issues with the docs site. I also plan to write more for some of the other pain points I found, like Google BigQuery.</p>
<p>My last milestone was to create a use case for a data visualization course at RIT. While I didn&rsquo;t implement my basic reports, I did create the proposal and make an effort to write new statistics. There&rsquo;s a lot of potential now to work with the data in Google BigQuery and do front-end work with tools like <a href="https://d3js.org/">D3.js</a> and <a href="https://plot.ly/javascript/">Plotly.js</a>. I believe there&rsquo;s significant potential to use ListenBrainz as a hands-on project for students to explore data visualization with real data. I hope to support my independent study professor, Prof. Roberts, with questions and logistics of using it as a tool for learning in the future.</p>

<h4 id="unexpected-success">Unexpected success&nbsp;<a class="hanchor" href="#unexpected-success" aria-label="Anchor link for: Unexpected success">🔗</a></h4>
<p>I also think I had an unplanned success too. I immersed myself in the community for ListenBrainz too. Over the last few months, I realized that many of my strengths are in community management and tooling. During my time in the community, I did the following:</p>
<ul>
<li><a href="https://github.com/metabrainz/listenbrainz-server/pull/290">Fixed SELinux labels in Docker</a></li>
<li><a href="https://github.com/metabrainz/listenbrainz-server/pull/288">Contributed a pull request template</a></li>
<li><a href="https://github.com/metabrainz/listenbrainz-server/pull/287">Drafted contributing guidelines</a></li>
<li><a href="https://github.com/metabrainz/listenbrainz-server/pull/294">Fixed a PostgreSQL bug</a></li>
<li><a href="https://github.com/metabrainz/listenbrainz-server/pulls?utf8=%E2%9C%93&amp;q=is%3Apr&#43;author%3Ajflory7&#43;">And more…</a></li>
</ul>

<h2 id="to-the-future">To the future!&nbsp;<a class="hanchor" href="#to-the-future" aria-label="Anchor link for: To the future!">🔗</a></h2>
<p>This ends my independent study with ListenBrainz, but it doesn&rsquo;t end my time contributing! I chose ListenBrainz because it&rsquo;s a project I&rsquo;m passionate about. An independent study allowed me to justify more time on it than a side project in my free time. I&rsquo;m happy to have that opportunity, but I don&rsquo;t want to end here!</p>
<p>I want to follow through on the statistics because I&rsquo;m passionate about understanding music listening trends. I think there&rsquo;s a lot of power for psychological research through music data. To this point, I filed a ticket to request <a href="https://tickets.metabrainz.org/browse/LB-243">tagging listens with &ldquo;emotion&rdquo; words</a> that are synced back to <a href="https://musicbrainz.org/doc/MusicBrainz_Database">MusicBrainz entities</a>.</p>
<p>I won&rsquo;t have as much time to work on the project without the course credit, but I hope to stay involved for the future. I love the project and I love the community. I&rsquo;m thankful for the opportunity to work on this project as an independent study, and learn some things along the way.</p>]]></description></item><item><title>ListenBrainz community gardening and user statistics</title><link>https://jwheel.org/blog/2017/11/listenbrainz-community-user-statistics/</link><pubDate>Mon, 13 Nov 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/11/listenbrainz-community-user-statistics/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>My progress with ListenBrainz slowed, but I am resuming the pace of contributing and advancing on my independent study timeline. This past week, I finished out assigned tasks to discuss contributor-related documentation, like a Code of Conduct, contributor guidelines, and a pull request template. I began research on user statistics and found some already created. I wrote one of my own, but need to learn more about Google BigQuery to advance further.</p>

<h2 id="paving-the-contributor-pathway">Paving the contributor pathway&nbsp;<a class="hanchor" href="#paving-the-contributor-pathway" aria-label="Anchor link for: Paving the contributor pathway">🔗</a></h2>
<p>
<figure>
  <img src="/blog/2017/11/Screenshot-from-2017-11-13-02-05-12.png" alt="Making it easier for people to contribute user statistics to ListenBrainz" loading="lazy">
  <figcaption>Making it easier for people to contribute to ListenBrainz with helpful contibuting guidelines</figcaption>
</figure>
</p>
<p>Earlier, I identified weaknesses for the ListenBrainz contributor pathway and found ways we could improve the pathway. This started with the development environment documentation. Now, I helped draft first revisions of our <a href="https://github.com/metabrainz/listenbrainz-server/pull/287">contributor guidelines</a>, <a href="https://github.com/metabrainz/listenbrainz-server/pull/286">Code of Conduct reference</a>, and <a href="https://github.com/metabrainz/listenbrainz-server/pull/288">pull request templates</a>. Together, these three documents have two goals.</p>
<ol>
<li><strong>Make it easier</strong> to contribute to ListenBrainz</li>
<li>Have a better experience and <strong>have fun</strong> contributing!</li>
</ol>
<p>Adding these documents addresses these goals. Additionally, the <a href="https://github.com/metabrainz/listenbrainz-server/community">GitHub community profile</a> also highlights these deliverables as ways to meet these goals. After getting feedback and seeing what others think, we make more revisions later (with some trial runs).</p>

<h2 id="back-to-selinux-context-flags">Back to SELinux context flags&nbsp;<a class="hanchor" href="#back-to-selinux-context-flags" aria-label="Anchor link for: Back to SELinux context flags">🔗</a></h2>
<p>Recently, I set my desktop back up and installed Docker for the first time on this machine; however, the development environment still failed to start. When I ran the script, it would eventually error out because of a permission denial. The web server image for ListenBrainz was failing.</p>
<p>After debugging, I noticed that I missed the SELinux volume tags for the ListenBrainz web server images in my original pull request, <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">#257</a>. When I created the pull request, I might have had cached data that let my laptop run the development environment without a problem. In either case, it was an easy fix and I knew what the issue was when it happened. Therefore, I submitted a new fix in <a href="https://github.com/metabrainz/listenbrainz-server/pull/290">#290</a>.</p>

<h2 id="writing-new-user-statistics">Writing new user statistics&nbsp;<a class="hanchor" href="#writing-new-user-statistics" aria-label="Anchor link for: Writing new user statistics">🔗</a></h2>
<p>The most interesting part of my independent study is working with the music data to build and generate interesting statistics. I finally began exploring the <a href="https://github.com/metabrainz/listenbrainz-server/tree/master/listenbrainz/stats">existing statistics</a> in ListenBrainz. The statistic queries use BigQuery standard SQL. BigQuery helps rapidly scan and scale data queries to help with performance (I have a lot to learn about BigQuery).</p>

<h4 id="two-types-of-statistics">Two types of statistics&nbsp;<a class="hanchor" href="#two-types-of-statistics" aria-label="Anchor link for: Two types of statistics">🔗</a></h4>
<p>Additionally, ListenBrainz generates <strong>two types</strong> of statistics:</p>
<ol>
<li>Site-wide statistics</li>
<li>User statistics</li>
</ol>
<p>Site-wide statistics are metrics non-specific to a single user. There is only <a href="https://github.com/metabrainz/listenbrainz-server/blob/master/listenbrainz/stats/sitewide.py">one site-wide query</a> now. It counts how many artists were ever submitted to this ListenBrainz instance and returns an integer. There&rsquo;s room for expansion in site-wide statistics.</p>
<p>On the other hand, user statistics are metrics specific to a single user. There&rsquo;s a <a href="https://github.com/metabrainz/listenbrainz-server/blob/master/listenbrainz/stats/user.py">fair number already</a>, like the top artists and songs in a time period and the number of artists you&rsquo;ve listened to. These are a little more complete and offer more expansion for doing cool front-end work with something like <a href="https://d3js.org/">D3.js</a>.</p>

<h4 id="writing-user-statistics">Writing user statistics&nbsp;<a class="hanchor" href="#writing-user-statistics" aria-label="Anchor link for: Writing user statistics">🔗</a></h4>
<p>Of course, I had to try writing my own. One helpful query I thought of was getting a count of the songs you listened to over a time period (e.g. &ldquo;you listened to 500 songs this week!&rdquo;). I haven&rsquo;t tested it yet, but I have this in a local branch and hope to test it with real data soon.</p>
<pre tabindex="0"><code>def get_play_count(musicbrainz_id, time_interval=None): 
 
 filter_clause = &#34;&#34; 
 if time_interval: 
     filter_clause = &#34;AND listened_at &gt;=
     TIMESTAMP_SUB(CURRENT_TIME(), 
     INTERVAL {})&#34;.format(time_interval) 
 
 query = &#34;&#34;&#34;SELECT COUNT(release_msid) as listen_count 
            FROM {dataset_id}.{table_id} 
            WHERE user_name = @musicbrainz_id 
            {time_filter_clause} 
            LIMIT {limit} 
         &#34;&#34;&#34;.format( 
                 dataset_id=config.BIGQUERY_DATASET_ID, 
                 table_id=config.BIGQUERY_TABLE_ID, 
                 time_filter_clause=filter_clause, 
                 limit=config.STATS_ENTITY_LIMIT, 
            ) 
 
 parameters = [ 
     { 
         &#39;type&#39;: &#39;STRING&#39;, 
         &#39;name&#39;: &#39;musicbrainz_id&#39;, 
         &#39;value&#39;: musicbrainz_id 
     } 
 ] 
 
 return stats.run_query(query, parameters)
</code></pre>
<h2 id="researching-google-bigquery">Researching Google BigQuery&nbsp;<a class="hanchor" href="#researching-google-bigquery" aria-label="Anchor link for: Researching Google BigQuery">🔗</a></h2>
<p>My next steps for the independent study are researching <a href="https://cloud.google.com/bigquery/docs/">Google BigQuery</a>. After going through the existing statistics and understanding how ListenBrainz generates them, an understanding of Google BigQuery is essential to writing effective queries. When I become more comfortable with the tooling and how it works, I want to map out a plan of statistics to generate and measure.</p>
<p>Until then, the hacking continues! As always, keep the FOSS flag high…</p>]]></description></item><item><title>Exploring Google Code-In, ListenBrainz easyfix bugs, D3.js</title><link>https://jwheel.org/blog/2017/10/google-code-in-listenbrainz-d3-js/</link><pubDate>Sat, 21 Oct 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/10/google-code-in-listenbrainz-d3-js/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>Last week moved quickly for me in ListenBrainz. I submitted multiple pull requests and participated in the weekly developer&rsquo;s meeting on Monday. I was also invited to take part as a mentor for ListenBrainz for the upcoming round of Google Code-In! In addition to my changes and new role as a mentor, I&rsquo;m researching libraries like D3.js to help build visualizations for music data.  Suddenly, everything started moving fast!</p>

<h2 id="last-week-recap">Last week: Recap&nbsp;<a class="hanchor" href="#last-week-recap" aria-label="Anchor link for: Last week: Recap">🔗</a></h2>
<p>The ListenBrainz team accepted my <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">development environment improvements</a> and <a href="https://github.com/metabrainz/listenbrainz-server/pull/259">documentation</a>. This gave me an opportunity to better explore project documentation tools. I experimented with <a href="http://www.sphinx-doc.org/en/stable/">Sphinx</a> and <a href="https://readthedocs.org/">Read the Docs</a>. Sphinx introduced me to <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> for documentation formats. I&rsquo;ve avoided it in favor of Markdown for a long time, but I see where reStructuredText is stronger for advanced documentation.</p>
<p>Since ListenBrainz is a new project, I plan to contribute documentation for any of my work and improve documentation for pre-existing work. One of the goals for this independent study is to make ListenBrainz a viable candidate for a future data analysis course. To make it easy to use and understand, ListenBrainz needs excellent documentation. Since one of my strengths is technical writing, I plan to contribute more documentation this semester.</p>
<p>You can see some of the <a href="https://listenbrainz.readthedocs.io/en/master/">new documentation</a> already!</p>

<h2 id="google-code-in-mentor">Google Code-In mentor&nbsp;<a class="hanchor" href="#google-code-in-mentor" aria-label="Anchor link for: Google Code-In mentor">🔗</a></h2>
<p>The MetaBrainz community manager, <a href="https://musicbrainz.org/user/Freso">Freso Olesen</a>, approached me to mentor for Google Code-In. <a href="https://codein.withgoogle.com/">Google Code-In</a> is an opportunity for teenagers to meaningfully contribute to open source projects. Google describes Google Code-In as…</p>
<blockquote>
<p>Pre-university students ages 13 to 17 are invited to take part in Google Code-in: Our global, online contest introducing teenagers to the world of open source development. With a wide variety of bite-sized tasks, it’s easy for beginners to jump in and get started no matter what skills they have.</p>
<p>Mentors from our participating organizations lend a helping hand as participants learn what it’s like to work on an open source project. Participants get to work on real software and win prizes from t-shirts to a trip to Google HQ!</p>
</blockquote>
<p>MetaBrainz is a participating organization of Google Code-In this cycle. Because of my work with ListenBrainz, I will contribute a few hours a week to help mentor participating students with ListenBrainz. Beginner problems should be easy to help with since I&rsquo;m still beginning too, and as I spend more time with ListenBrainz, I can help with harder problems.</p>
<p>I&rsquo;m excited to give back to one of my favorite open source projects in this way! I&rsquo;m grateful to have this chance to help out during Google Code-In.</p>

<h2 id="choosing-easyfix-bugs">Choosing easyfix bugs&nbsp;<a class="hanchor" href="#choosing-easyfix-bugs" aria-label="Anchor link for: Choosing easyfix bugs">🔗</a></h2>
<p>After I figured out the development environment issues, I went through <a href="https://tickets.metabrainz.org/projects/LB/issues/">open tickets</a> filed against ListenBrainz to find some to work on. I made a preliminary pass through all open tickets and left some comments for more information, when needed. The tickets I highlighted to look into next were</p>
<ul>
<li><a href="https://tickets.metabrainz.org/browse/LB-85"><strong>LB-85</strong></a>: Username in the profile URL should be case insensitive</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-124"><strong>LB-124</strong></a>: Install messybrainz as a a python library from requirements</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-176"><strong>LB-176</strong></a>: Add stats module and begin calculating some user stats from BigQuery</li>
<li><strong><a href="https://tickets.metabrainz.org/browse/LB-206">LB-206</a></strong>: &ldquo;playing_now&rdquo; submissions not showing on profile</li>
<li><a href="https://tickets.metabrainz.org/browse/LB-212"><strong>LB-212</strong></a>: Show the MetaBrainz logo on the listenbrainz footer.</li>
</ul>
<p>Of these five, LB-124 and LB-212 are already closed. While drafting this article, I completed LB-124 in <a href="https://github.com/metabrainz/listenbrainz-server/pull/266">PR #266</a>. This was part of a test to get the documentation building again because of odd import errors. Later, a new student also learning the project for the first time asked to work on LB-212. Since it was a good first task to explore the project code, I passed the ticket to him.</p>
<p>I want to do one more &ldquo;easyfix&rdquo; bug before going into the main part of my independent study timeline. I don&rsquo;t yet feel comfortable with the code and one more bug solved will help. After this, I plan to pursue the heavier lifting of the independent study to explore data operations and queries to make.</p>

<h2 id="researching-d3js">Researching D3.js&nbsp;<a class="hanchor" href="#researching-d3js" aria-label="Anchor link for: Researching D3.js">🔗</a></h2>
<p>Prof. Roberts introduced <a href="https://d3js.org/">D3.js</a> as a library to build interactive, dynamic charts and visual representations of data. I haven&rsquo;t yet looked into much front-end work, but this was a cool project that I wanted to highlight in my weekly report. This feels like it could be a powerful match for ListenBrainz, especially since the data has high detail.</p>

<h2 id="upcoming-activity">Upcoming activity&nbsp;<a class="hanchor" href="#upcoming-activity" aria-label="Anchor link for: Upcoming activity">🔗</a></h2>
<p>This next week, I won&rsquo;t have as much time to contribute to ListenBrainz. On October 21, I&rsquo;m traveling to Raleigh, NC for <a href="https://allthingsopen.org/">All Things Open</a>. On October 24, I <a href="https://allthingsopen.org/speakers/justin-w-flory/">present my talk</a>, &ldquo;<em>What open source and J.K. Rowling have in common</em>&rdquo;. Since I&rsquo;ll be out of Rochester and missing other classwork, I expect less time on my ListenBrainz work.</p>
<p>This next week will be slower than the last two weeks. Hopefully I&rsquo;ll learn something at the conference too to bring back for ListenBrainz.</p>
<p>Until then… keep the FOSS flag high.</p>]]></description></item><item><title>How to set up a ListenBrainz development environment</title><link>https://jwheel.org/blog/2017/10/listenbrainz-development-environment/</link><pubDate>Wed, 04 Oct 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/10/listenbrainz-development-environment/</guid><description><![CDATA[<p><em>This post is part of a series of posts where I contribute to the ListenBrainz project for my independent study at the Rochester Institute of Technology in the fall 2017 semester. For more posts, find them in <a href="/tags/rit-2171/">this tag</a>.</em></p>
<hr>
<p>One of the first rites of passage when working on a new project is creating your development environment. It always seems simple, but sometimes there are bumps along the way. The first activity I did to begin contributing to ListenBrainz was create my development environment. I wasn&rsquo;t successful with the documentation in the README, so I had to play around and work with the project before I was even running it.</p>
<p>The first part of this post details how to set up your own development environment. Then, the second half talks about the solution I came up with and my first contribution back to the project.</p>

<h2 id="install-dependencies-docker">Install dependencies: Docker&nbsp;<a class="hanchor" href="#install-dependencies-docker" aria-label="Anchor link for: Install dependencies: Docker">🔗</a></h2>
<p>This tutorial assumes you are using a Linux distribution. If you&rsquo;re using a different operating system, install the necessary dependencies or packages with your preferred method.</p>
<p>ListenBrainz ships in Docker containers, which helps create your development environment and later deploy the application. Therefore, to work on the project, you need to install Docker and use containers for building the project. Containers save you from installing all of this on your own workstation! Since I&rsquo;m using Fedora, I run this command.</p>
<pre tabindex="0"><code>sudo dnf install docker docker-compose
</code></pre>
<h2 id="register-a-musicbrainz-application">Register a MusicBrainz application&nbsp;<a class="hanchor" href="#register-a-musicbrainz-application" aria-label="Anchor link for: Register a MusicBrainz application">🔗</a></h2>
<p>Next, you need to register your application and get a OAuth token from MusicBrainz. Using the OAuth token lets you sign into your development environment with your MusicBrainz account. Then, you can import your plays from somewhere else.</p>
<p>To register, visit the <a href="https://musicbrainz.org/account/applications">MusicBrainz applications page</a>. There, look for the option to <a href="https://musicbrainz.org/account/applications/register">register your application</a>. Fill out the form with these three options.</p>
<ul>
<li><strong>Name</strong>: (any name you want and will recognize, I used <code>listenbrainz-server-devel</code>)</li>
<li><strong>Type</strong>: <code>Web Application</code></li>
<li><strong>Callback URL</strong>: <code>http://localhost/login/musicbrainz/post</code></li>
</ul>
<p>After entering this information, you&rsquo;ll have a OAuth client ID and OAuth client secret. You&rsquo;ll use these for configuring ListenBrainz.</p>

<h4 id="update-configpy">Update config.py&nbsp;<a class="hanchor" href="#update-configpy" aria-label="Anchor link for: Update config.py">🔗</a></h4>
<p>With your new client ID and secret, update the ListenBrainz configuration file. If this is your first time configuring ListenBrainz, copy the sample to a live configuration.</p>
<pre tabindex="0"><code>cp listenbrainz/config.py.sample listenbrainz/config.py
</code></pre><p>Next, open the file with your favorite text editor and look for this section.</p>
<pre tabindex="0"><code># MusicBrainz OAuth
MUSICBRAINZ_CLIENT_ID = &#34;CLIENT_ID&#34;
MUSICBRAINZ_CLIENT_SECRET = &#34;CLIENT_SECRET&#34;
</code></pre><p>Update the strings with your client ID and secret. After doing this, your ListenBrainz development environment is able to authenticate and log in from your MusicBrainz login.</p>

<h2 id="initialize-listenbrainz-databases">Initialize ListenBrainz databases&nbsp;<a class="hanchor" href="#initialize-listenbrainz-databases" aria-label="Anchor link for: Initialize ListenBrainz databases">🔗</a></h2>
<p>Your development environment needs some databases present to work. Before proceeding, run these three commands to initialize the databases.</p>
<pre tabindex="0"><code>docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_db --create-db
docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_msb_db --create-db
docker-compose -f docker/docker-compose.yml -p listenbrainz run --rm web python3 manage.py init_influx
</code></pre><p>Your development environment is now ready. Now, let&rsquo;s actually see ListenBrainz load locally!</p>

<h2 id="run-the-magic-script">Run the magic script&nbsp;<a class="hanchor" href="#run-the-magic-script" aria-label="Anchor link for: Run the magic script">🔗</a></h2>
<p>Once you have done this, run the <code>develop.sh</code> script in the root of the repository. Using <code>docker-compose</code>, the script creates multiple Docker containers for the different services and parts of the ListenBrainz server. Running this script will start Redis, PostgreSQL, InfluxDB, and web server containers, to name a few. But this also makes it easy to stop them all later.</p>
<pre tabindex="0"><code>./develop.sh
</code></pre><p>You will see the containers build and eventually run. Leave the script running to see your development environment. Later, you can shut it down by pressing <code>CTRL^C</code>. Once everything is running, visit your new site from your browser!</p>
<p><a href="http://localhost/">http://localhost/</a></p>
<p>Now, you are all set to begin making changes and testing them in your development environment!</p>

<h2 id="making-my-first-pull-request">Making my first pull request&nbsp;<a class="hanchor" href="#making-my-first-pull-request" aria-label="Anchor link for: Making my first pull request">🔗</a></h2>
<p>As mentioned earlier, my first attempt at a development environment was unsuccessful. My system kept denying permission to the processes in the containers. After looking at system audit logs and running a temporary <code>setenforce 0</code>, I tried the script one more time. Everything suddenly worked! So the issue was mostly with SELinux.</p>
<p>With my goal to get my environment set up, I figured out a few issues with the configuration offered by the project developers. I eventually made <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">PR #257</a> against <code>listenbrainz-server</code> with my improvements.</p>

<h4 id="labeling-selinux-volume-mounts">Labeling SELinux volume mounts&nbsp;<a class="hanchor" href="#labeling-selinux-volume-mounts" aria-label="Anchor link for: Labeling SELinux volume mounts">🔗</a></h4>
<p>To diagnose the issue, I started with a quick search and found a <a href="https://stackoverflow.com/questions/24288616/permission-denied-on-accessing-host-directory-in-docker">StackOverflow question</a> with my same problem. There, the question was about Docker containers and denied permissions in the container. The answers explained it was an SELinux error and the context for the containers was not set. However, temporarily changing context for a directory didn&rsquo;t seem too effective and doesn&rsquo;t persist across reboots.</p>
<p>Continuing the search, I found an issue filed against <code>docker-compose</code> about the <code>:z</code> and <code>:Z</code> flags for volume mounts. These flags set SELinux context for containers, with the best explanation I found coming from <a href="https://stackoverflow.com/a/35222815/2497452">this StackOverflow answer</a>.</p>
<blockquote>
<p>Two suffixes :z or :Z can be added to the volume mount. These suffixes tell Docker to relabel file objects on the shared volumes. The &lsquo;z&rsquo; option tells Docker that the volume content will be shared between containers. Docker will label the content with a shared content label. Shared volumes labels allow all containers to read/write content. The &lsquo;Z&rsquo; option tells Docker to label the content with a private unshared label.</p>
</blockquote>
<p>Therefore, I added the <code>:z</code> flag to all the volume mounts in the <code>docker-compose.yml</code> file. I submitted a fix upstream for this in <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">listenbrainz-server#257</a>!</p>

<h4 id="correct-the-startup-port">Correct the startup port&nbsp;<a class="hanchor" href="#correct-the-startup-port" aria-label="Anchor link for: Correct the startup port">🔗</a></h4>
<p>In the README, it says the server will start on port 8000, but the <code>docker-compose.yml</code> file actually started the server on port 80. I included a fix for this in <a href="https://github.com/metabrainz/listenbrainz-server/pull/257">my pull request</a> as well.</p>

<h2 id="git-push">git push!&nbsp;<a class="hanchor" href="#git-push" aria-label="Anchor link for: git push!">🔗</a></h2>
<p>This post makes a debugging experience that actually took hours look like it happened in minutes. But after getting over this hurdle, it was awesome to finally see ListenBrainz running locally on my workstation. It was an even better feeling when I could take my improvements and send them back in a pull request to ListenBrainz. Hopefully this will make it easier for others to create their own development environments and start hacking!</p>]]></description></item><item><title>On the data refrain: Contributing to ListenBrainz</title><link>https://jwheel.org/blog/2017/10/contributing-listenbrainz/</link><pubDate>Mon, 02 Oct 2017 00:00:00 +0000</pubDate><guid>https://jwheel.org/blog/2017/10/contributing-listenbrainz/</guid><description><![CDATA[<p>A unique opportunity of attending an open source-friendly university is when course credits and working on open source projects collide. This semester, I&rsquo;m participating in an independent study at the <a href="https://www.rit.edu/">Rochester Institute of Technology</a> where I will contribute to the <a href="https://listenbrainz.org/">ListenBrainz</a> project.</p>
<p>Many students take part in independent studies where they work on their own projects. However, in the spirit of open source collaboration, I wanted to contribute to a project that already existed. That way, my work would be helpful to a real-world project where it would have a value even after the end of the semester. Additionally, I wanted  a project to help me sharpen my Python skill. And ListenBrainz was a fun, exciting candidate for this.</p>

<h2 id="objectives">Objectives&nbsp;<a class="hanchor" href="#objectives" aria-label="Anchor link for: Objectives">🔗</a></h2>
<p>The independent study proposal included three primary goals I hoped to meet during this independent study:</p>
<ol>
<li><strong>Add basic reports</strong> to ListenBrainz from listening history data for top songs / artists / albums of week, month, year, etc.</li>
<li><strong>Create documentation</strong> to improve ease to use and develop for the ListenBrainz project</li>
<li>Offer as a <strong>use case for the data visualization course</strong> in fall 2018 with instructions on how to use the data</li>
</ol>

<h4 id="add-basic-reports">Add basic reports&nbsp;<a class="hanchor" href="#add-basic-reports" aria-label="Anchor link for: Add basic reports">🔗</a></h4>
<p>Methods for generating basic reports, charts, and statistics about listening history are important. They help make ListenBrainz a more interesting platform for a casual music listener, not just a developer. Therefore, my goal was to add a way to add basic reports or specific metrics for presenting to the user in the front-end.</p>
<p>As a stretch goal, if I have extra time, I would work on generating content (e.g. charts / graphs / statistics) to show the user in the front-end.</p>

<h4 id="documentation">Documentation&nbsp;<a class="hanchor" href="#documentation" aria-label="Anchor link for: Documentation">🔗</a></h4>
<p>Documentation is something near and dear to me. I enjoy making it easier for other people to use a project or get started with contributing. Therefore, I will contribute some time as a technical writer and help improve documentation on the project. This includes improving existing documentation, like how to set up a development environment, or creating new content.</p>
<p>As an end deliverable, it would be nice to have someone who has never worked with the project run get a development environment set up, import some data, and see something presented to them. Good documentation is key to making something like this possible.</p>

<h4 id="use-case-for-data-course">Use case for data course&nbsp;<a class="hanchor" href="#use-case-for-data-course" aria-label="Anchor link for: Use case for data course">🔗</a></h4>
<p>RIT will offer a data visualization course in future semesters and it would be helpful if ListenBrainz could be a use case or even tool for the course. Then, students could work with ListenBrainz for creating different visualizations for the music data. And maybe contribute some of their visualizations back upstream! For this to happen, we need comprehensive documentation and complete features.</p>
<p>A focus includes making ListenBrainz a good fit for this course.</p>

<h2 id="learn-more-about-listenbrainz">Learn more about ListenBrainz&nbsp;<a class="hanchor" href="#learn-more-about-listenbrainz" aria-label="Anchor link for: Learn more about ListenBrainz">🔗</a></h2>
<p>For the next few months, until December, I will blog regularly about contributing to the ListenBrainz project and my progress. Additionally, more posts about MusicBrainz, other MetaBrainz projects, or music data may follow. I&rsquo;m hoping to either create new or improve old documentation as well, so I plan to write often anyways!</p>
<p>For now, you can learn a bit more about ListenBrainz and other projects in the MetaBrainz family, like MusicBrainz.</p>
<ul>
<li><a href="https://listenbrainz.org/">ListenBrainz</a></li>
<li><strong>GitHub</strong>: <a href="https://github.com/metabrainz/listenbrainz-server">metabrainz/listenbrainz-server</a></li>
<li><a href="https://musicbrainz.org/doc/About">About MusicBrainz</a></li>
<li><a href="https://metabrainz.org/about">About MetaBrainz</a></li>
</ul>]]></description></item></channel></rss>