<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: MegaWatts</title>
    <description>The latest articles on Forem by MegaWatts (@megawatts).</description>
    <link>https://forem.com/megawatts</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1705090%2F31bab9e4-fba8-42a5-8444-75e3f22ca0d5.png</url>
      <title>Forem: MegaWatts</title>
      <link>https://forem.com/megawatts</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/megawatts"/>
    <language>en</language>
    <item>
      <title>Overcoming Challenges</title>
      <dc:creator>MegaWatts</dc:creator>
      <pubDate>Sun, 30 Jun 2024 00:22:06 +0000</pubDate>
      <link>https://forem.com/megawatts/overcoming-challenges-4bad</link>
      <guid>https://forem.com/megawatts/overcoming-challenges-4bad</guid>
      <description>&lt;p&gt;Solving complex problems is more than just a technical challenge; it’s a journey of continuous learning and growth. As a growing backend developer, I’ve always been driven by the desire to develop efficient, scalable, and maintainable server-side logic. Recently, I faced a challenge that tested my skills, thought process, and determination.&lt;/p&gt;

&lt;p&gt;I was tasked with optimizing the business logic at the server-side for an equipment management system. Equipment are to be serviced based on data from different components of the equipment inputted by the user. Initially, the criteria for servicing an equipment were based on the engine and tire components. Management decided to add another criterion for servicing, which added to the complexity of the system.&lt;/p&gt;

&lt;p&gt;At that time, the existing implementation of the logic wasn’t up to par. It lacked reusability, separation of concerns, and was difficult to understand. Here are the steps I took to solve the challenge:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand the Requirements&lt;/strong&gt;&lt;br&gt;
Before diving into coding, I made a concerted effort to understand the requirements of the system. This included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The functionality the system needs to provide.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The various modules or components required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How these components will interact with each other.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Identify Core Components&lt;/strong&gt;&lt;br&gt;
I identified the core components of the system. An equipment was modeled as a class using other components like engine, tire, and fuel consumption properties. Each component represented a distinct part of the functionality:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Equipment Management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Component Management&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Service Management&lt;br&gt;
A UML Class Diagram to state the relationships between classes was created.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgl5p6x96pniqzlszamwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgl5p6x96pniqzlszamwh.png" alt="UML Class diagram" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define Responsibilities Clearly&lt;/strong&gt;&lt;br&gt;
Each class was designed to have a single responsibility. This approach makes classes easier to understand, maintain, and reuse. For example:&lt;/p&gt;

&lt;p&gt;The Equipment class handles general equipment details.&lt;br&gt;
The Engine class manages engine-specific properties and behaviors.&lt;br&gt;
The ServiceManager class handles the logic for determining when an equipment needs servicing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Interfaces and Abstract Classes&lt;/strong&gt;&lt;br&gt;
Interfaces and abstract classes help in defining contracts and promoting code reuse. I used them to outline the basic structure and functionality that concrete classes should implement.&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

class Component(ABC):
    @abstractmethod
    def needs_service(self) -&amp;gt; bool:
        pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Implement Concrete Classes&lt;/strong&gt;&lt;br&gt;
I implemented the concrete classes that adhere to the interfaces or extend the abstract classes. This ensures that the classes are consistent and reusable.&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Engine(Component):
    def __init__(self, hours_run: int):
        self.hours_run = hours_run

    def needs_service(self) -&amp;gt; bool:
        return self.hours_run &amp;gt; 1000

class Tire(Component):
    def __init__(self, wear_level: float):
        self.wear_level = wear_level

    def needs_service(self) -&amp;gt; bool:
        return self.wear_level &amp;gt; 0.8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use Design Patterns&lt;/strong&gt;&lt;br&gt;
I studied and implemented design patterns to promote reusability and simplicity. Using the Factory pattern, I was able to produce reusable and simple components.&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ComponentFactory:
    @staticmethod
    def create_component(component_type: str, **kwargs) -&amp;gt; Component:
        if component_type == "engine":
            return Engine(**kwargs)
        elif component_type == "tire":
            return Tire(**kwargs)
        else:
            raise ValueError("Unknown component type")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Keep It Simple&lt;/strong&gt;&lt;br&gt;
I adhered to the KISS principle by ensuring each class does one thing and does it well. This made the codebase easier to understand and maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write Tests&lt;/strong&gt;&lt;br&gt;
I wrote unit tests for each class to ensure they work as expected. This also makes future changes easier and safer.&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import unittest

class TestEngine(unittest.TestCase):
    def test_needs_service(self):
        engine = Engine(hours_run=1200)
        self.assertTrue(engine.needs_service())

if __name__ == "__main__":
    unittest.main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, I was able to create classes that adhere to the KISS principle, making the codebase easier to maintain and extend. The result of refactoring the code was a dramatic improvement in the application's design. It became easy to understand, maintain, and extend. This experience not only solved a critical problem but also deepened my understanding of software design principles.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://hng.tech/internship"&gt;HNG Internship&lt;/a&gt; is a fast-paced boot camp for learning digital skills, and being part of it means being surrounded by a community of like-minded individuals who are equally passionate about technology.&lt;/p&gt;

&lt;p&gt;My journey with HNG started with a simple desire to improve my skills. The opportunity to work on real-world projects, collaborate with talented developers, and receive mentorship from industry experts is invaluable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hng.tech/hire"&gt;HNG Hire&lt;/a&gt; makes it easy to find and hire elite talent.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>First glance - Sales Dataset</title>
      <dc:creator>MegaWatts</dc:creator>
      <pubDate>Sat, 29 Jun 2024 23:00:03 +0000</pubDate>
      <link>https://forem.com/megawatts/first-glance-retail-sales-dataset-1235</link>
      <guid>https://forem.com/megawatts/first-glance-retail-sales-dataset-1235</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.kaggle.com/datasets/kyanyoga/sample-sales-data/data"&gt;sales dataset&lt;/a&gt; is a collection of orders made by different customers from various geographical are&lt;code&gt;[CITY,STATE,POSTALCODE,COUNTRY]&lt;/code&gt;. Each entry includes detailed information about the customer &lt;code&gt;[CUSTOMERNAME, CONTACTLASTNAME    CONTACTFIRSTNAME]&lt;/code&gt;, the order &lt;code&gt;[ORDERNUMBER, DATE, STATUS]&lt;/code&gt;, and the products ordered &lt;code&gt;[PRODUCTLINE, MSRP, PRODUCTCODE]&lt;/code&gt;. This dataset spans from 2003 to 2005 and includes contact person information.&lt;/p&gt;

&lt;p&gt;Each entry contains an order number&lt;code&gt;[ORDERNUMBER]&lt;/code&gt; which represents a unique identifier for each order. An order entry contains different products &lt;code&gt;[PRODUCTCODE]&lt;/code&gt; associated with a product line &lt;code&gt;[PRODUCTLINE]&lt;/code&gt;. &lt;br&gt;
Data columns such as deal size &lt;code&gt;[DEALSIZE]&lt;/code&gt; and status &lt;code&gt;[STATUS]&lt;/code&gt; are used to categorize different products. The dataset includes pricing &lt;code&gt;[PRICEEACH]&lt;/code&gt;, quantity ordered &lt;code&gt;[QUANTITYORDERED]&lt;/code&gt;, and the total sales amount &lt;code&gt;[SALES]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The dataset contains 2823 entries of orders with 25 data columns, of which 9 are numerical and 3 are categorical data &lt;code&gt;[STATUS, DEALSIZE, PRODUCTLINE]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fda5dgk3a3f725n6nu3pz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fda5dgk3a3f725n6nu3pz.png" alt="retail sales data dataset's main statistical properties" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fig. 1 showing retail sales data dataset's main statistical properties&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Components of the Dataset:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Customer Information: &lt;code&gt;[CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Geographical Information: &lt;code&gt;[ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, TERRITORY]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Order Information: &lt;code&gt;[ORDERNUMBER, ORDERDATE, STATUS]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Product Information: &lt;code&gt;[PRODUCTLINE, PRODUCTCODE, QUANTITYORDERED, PRICEEACH, SALES]&lt;/code&gt;&lt;br&gt;
• Additional Attributes: &lt;code&gt;[QTR_ID, MONTH_ID, YEAR_ID, MSRP, DEALSIZE]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fora2o6qch3v2nbl5o99v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fora2o6qch3v2nbl5o99v.png" alt="shape of the retail sales data" width="176" height="34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fig 2 shows the shape of the retail sales data&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose of the Review&lt;/strong&gt;&lt;br&gt;
 The purpose of this review is to provide an initial understanding of the dataset's structure, content, and data quality. This will help to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Detect missing values and assess their impact.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify necessary data type conversions for accurate analysis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Determine important columns for analysis such as sales figures, order details, and customer information.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Observations&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Multiple Products per Order:
An ORDERNUMBER may be associated with more than one product &lt;code&gt;[PRODUCTCODE]&lt;/code&gt; from different product lines &lt;code&gt;[PRODUCTLINE]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Sales Calculation Discrepancy:
The &lt;code&gt;[SALES]&lt;/code&gt; column is not always the multiplication of the &lt;code&gt;[QUANTITYORDERED]&lt;/code&gt;and &lt;code&gt;[PRICEEACH]&lt;/code&gt; columns. There are 1304 entries that do not follow this calculation.&lt;/li&gt;
&lt;li&gt;Order Date Format:
The &lt;code&gt;[ORDERDATE]&lt;/code&gt; is in object format and will need to be converted to a datetime format for any time series analysis.&lt;/li&gt;
&lt;li&gt;Inconsistent Phone Data:
The &lt;code&gt;[PHONE]&lt;/code&gt; data does not follow a consistent pattern across different countries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Potential Areas for Further Analysis:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Sales Performance:

&lt;ul&gt;
&lt;li&gt;
Analyze completed sales data over time, by product, and by region.
&lt;/li&gt;
&lt;li&gt;
Analyze sales data based on status by product, region, and time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Customer Insights:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Segment customers and analyze their purchasing behavior.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Geographical Insights:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Map sales data and customer locations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Forecasting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Predict quantity and product sales for the next year.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am currently an intern in the&lt;a href="https://hng.tech/internship"&gt; HNG Internship&lt;/a&gt; boot camp that builds apps and solves different problems in teams. The &lt;a href="https://hng.tech/internship"&gt;HNG Internship&lt;/a&gt; is a fast-paced boot camp for learning digital skills. &lt;a href="https://hng.tech/hire"&gt;HNG Hire&lt;/a&gt; makes it easy to find and hire elite talent.&lt;/p&gt;

</description>
      <category>learning</category>
      <category>datascience</category>
      <category>community</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
