Friday, April 30, 2021

Moving Images on a Tkinter Canvas

The stock analysis and comparator app I made was somewhat quick, just a few hours over a weekend. And most of that was just trying different things to formulate the data I wanted to see and compare. The latest project, will take some time and I'm not expecting it to be easy. Really looking forward to learning more how to use Tkinter and other packages that can be used with it.

Purpose of the application: I currently work in a helpdesk for a medium sized company. How we keep track of equipment and the frequency of moving things to different locations brings rise to a glaring need. How do we know where everything is physically located? Of course we have software to keep track of inventory and in what department it is supposedly located. We can also know what switch something is ultimately patched in to. But how do we know the physical location of each device? APs generally have a web UI where you can be place each one on a map. One could have a diagram of what each drop is labeled and where it is in the room. But that could still be a somewhat unclear as to where a PC, printer, or other device is located. I wanted to develop a simple application that would show a floor plan and a user could drag and drop different icons to show where each device is. It's entirely possible this exists but I am coding this to learn, not necessarily to market an application. Although if I were to develop it enough I would not be opposed to monetizing it someday.

What I've done so far: The first thing I wanted to make sure I could do was to drag and drop an image in a window. I figured if I can just write something to make that one thing work, then I can move on to whatever next function I needed to make the vision complete. Tkinter is a basic library for Python so I figured I would just start there. Through searching a few things I found a decent YouTube video series from codemy.com. One of his videos showed how to drag and drop an image. An issue I found with the way it is coded is that it basically creates a brand new image every time it moves (at least that's how I am understanding it). While I realize the final solution I found might technically do the same thing, I still needed the image to be an object of my own creation. Then I could put all the objects in a list and serialize certain attributes of the object to save them (Pickle might just be my next post). It also moved the image to wherever was clicked. I needed it to work so that it would only move when that particular image was clicked. After a decent amount of searching I finally came across something that worked!




























The first few lines are part of the initialization of the object, but the two functions in the snippet of the code will actually drag the object only when clicked and stop moving it when the mouse button is released. I admittedly don't fully understand how it works quite yet.

I believe the canvas.tag_bind binds the actual object to the mouse event and runs the code. Although I don't exactly understand what tag_bind does, it does seem to work fine. I am satisfied with how this part turned out. I just wanted to make the one thing work. Then I wanted to be able to save the locations of the images (I wanted to try this without a database). Then I could make a floor plan/blueprint and put that on the canvas. Then I would work on saving that in it's own folder. Next I want to be able to delete a device(image) or move it to a different floor plan, etc. Stay tuned for more progress on this!

25 Words or Less: You cannot write a whole program at once. Break it down and focus on completing one function, then continue to the next.





Thursday, April 15, 2021

Personal Application

Most of what I've coded so far was to solve a problem. Such as an efficiency system or documentation system. I recently have gotten in to trading. I started getting into it before GME craziness, so it's not like that was what got me into it. I was just curious about how it worked. I also had ideas earlier in 2020 of a few companies that I thought would do well, such as Zoom, and lo-and-behold, they did well and I could have made a decent return. So after making a few investments, some good some bad, and listening to a few podcasts I decided to do more research. This let me to want to look into companies' financials and balance sheets to make better decisions on what would be a more profitable, or potentially safer, investment. But after looking at a few companies I wanted to be able to compare companies. After looking at some data, to really compare I would have to write everything down. Which would be fine but I wanted something that would be quicker and would display the information I felt was most important.

Import yfinance python library.

From what I've read this is not the most reliable, but it is good to get started. Also the principles it uses would transfer to a more robust/reliable API. At least as far as what I read up on it, I felt it would not be a waste to write a small program to parse some data. So I just made a simple cli application. You put in any number of tickers and it compares YOY earnings and really any other data that I would have it return. The data is presented in a way that I feel most comfortable reading.

All in all, I feel it was a good little project. I could add more and may in the future and expand it any number of ways. At the moment however, I'm satisfied with how it works. It got me enough data for me to decide to invest in a particular restaurant company. QSR anyone? (not financial advice, or whatever one is supposed to say)

I'll have to see if I want to revisit this and make it more dynamic in the future, but I think it's good for now.

25 Words or Less: Simple and small programs can return important and profitable data.

Tuesday, April 6, 2021

Looking at Something From a Different Angle

As I thought about this post, I feel like I've written something to this effect before. Struggling with an issue when there is a very simple solution right in front of my face. Then finally seeing the more simple solution and implementing it. It does actually feel good in the end and that's what I will write about today.

I am developing a personal efficiency program. I enter certain activities and they have point values. I also put how many minutes I spend on each activity. Then when I look back I can see if I have been productive with my time and can make adjustments accordingly. I know it's impossible to reach, but 100% efficiency is the dream! I don't factor in my job or sleep, or even eating and such. But, things like watching TV is generally not efficient. Coding or studying Hindi on the other hand...

I designed it so that there is a database table for "ActivityTypes" and "ActivityEntries" I actually do. The problem is: what if an activity type is no longer valid and needs removed? Then I would have to have the program go through all entries that include that activity type and remove data from the column for an activity type on that row. Then before I knew it I was going down a rabbit hole of creating a new activity type of "Deleted Activity" and then using that to enter into the Activity Type column in the Entries table for when an Activity Type was deleted. That was just causing some confusion in my brain.

At last I had an epiphany of sorts. Why not just add a column in the Activity Type table for whether or not the activity type is valid/still in use or not? Then if an Entry had an activity type that was not valid it would just display a message letting the user know that the data might be inaccurate. That was very easy to implement. Then I just have 'activate' and 'deactivate' toggles if an Activity Type needs removed. It also makes it very easy to make an activity valid again. Data integrity is also there so that if something is deleted by mistake it can easily be undone.

Do you remember the scene in Big Hero 6 where Tadashi holds Hiro upside-down so he can get a new perspective and stimulate an idea? That's somewhat how I felt. Looking at the problem one way was not leading to progress. But doing something a completely new way gives just the inspiration needed to accomplish what was needed.

I know there will be bigger problems in the future. Ones that will require a different function or library to implement to solve a problem. If I keep in mind that there might just be a simple solution outside of my field of vision, I have to remember to lean back, or upside down perhaps, to find the obvious and easy solution.

25 Words or Less: Take a step back and try to see a problem from another angle. The solution might just be easier than you think.

Tuesday, March 30, 2021

Excel Is a Bane of Humankind

Excel is used by thousands, if not millions, of people every day and in all industries. It is a useful tool for what it is. The problem as I write this, I suppose, is not so much Excel itself but rather how it is used. Users expect it to be dependable. As they should. It's developed by one of the biggest companies in the world. But it should be used for what it is intended to be, a spreadsheet. What is Excel not?

A DATABASE!!!

Just to be clear. I understand it's not feasible for most companies to write a program for every nuanced situation. But when you have an enormous, and I mean ENORMOUS, spreadsheet that does calculations, uses macros made by the last person who had the job, and is needed for an absolutely integral cog in the function of your business, Excel is not what you need. You need a specialized program to handle that amount of data reliably. I've seen so many times where a macro gets corrupted, a file is corrupted, 32-bit version of office can't handle the processes needing done, etc. (Why programs still use 32-bit architecture is beyond me, but I guess companies have a financial limit on what they can realistically keep up to date.)

I've made a few simple web applications that handle a decent amount of data. I've used SQLite and PostgreSQL depending on the situation and they both work better than an Excel spreadsheet. I can customize it the way I need it and it is reliable. Of course, a database can be corrupted. But that's why you use a backup. (And I don't mean a person that doesn't know how to code making an Access program that runs like garbage.)

Again, while I realize that a niche application is not practical in every situation. For reliable data integrity and something that anyone can sit down and use, it is going to be best to have an application that stores data in a real database rather than an Excel spreadsheet. This may be just a rant posting, but it gives me impetus to keep coding. The fact that there is bad or misused software out there than can be improved upon. I will do what I can to make the world a better place by helping to rid the world (or at least myself) of the snare that is an Excel "database"

25 Words or Less: If you care about your data, do not use Excel to store it. Use a real database!

Monday, March 22, 2021

New Beginnings (again)

 I feel like I need to start this again. I know no one would really read this but I need a way to document things I learn. I have gotten into some coding again. I started making a documentation system last year and got to a point where I could try uploading it to AWS but had to put that on pause. Been a very busy since the last post. Started a helpdesk job at a different company. Took a trip to The Netherlands. Trying to learn Hindi. Busy getting everyone working from home at my job due to Covid. I developed a board game to a point that I'm somewhat happy with it. The game will just need a few more tweaks and play testing with those changes and maybe it can go to market someday. When the pandemic comes to an end I might be able to take it to some shops for people to play.

Just last week I started on an efficiency application to track how productive I am being. And thus why I want to start back at keeping track this way. Here is a problem I was having yesterday and how I resolved it.

I have a Flask application and on the one page I want to do an AJAX request. The AJAX request seemed to work as there were no errors. However, the page would always reload when clicking submit, so maybe the AJAX request wasn't going through. Through testing I found out that since the data was in a form, the form was being submitted to the backend before the AJAX request would ever be made. I removed the form tags and just used input fields with individual ids. The AJAX request would then send the data in those two fields to the backend.

I feel there is a better way to implement this as I believe form data can be sent through an AJAX request, but that might be for another day as this setup seems like it will work for this use case.

25 words or less: Having input fields not inside form tags can potentially make AJAX requests simpler.