Web-gui for Python logs

Logging can help you better understand the flow of a program and discover undesirable behaviour which you might not even consider while developing. Logs give you information about scenarios that an application is going through. You can label this information according to its importance: debug, info, warning and errors. Occurring errors can provide more insights than a stack trace by telling you what the program state was before it arrived at the line of code where the error occurred.

Logs browser in Flask
Logs browser in Flask

Continue reading “Web-gui for Python logs”

Calculating capital gains using FIFO queue

According to the first-in-first-out (FIFO) valuation method of capital gain, it’s assumed that equities are sold in the order in which they’re bought. In other words, the oldest shares are sold first. A detailed description of this method can be found in many places, e.g. here. In this post, I will focus on the implementation of the FIFO method in Python.

Fifo queue
Continue reading “Calculating capital gains using FIFO queue”

RSI stock screener

Stocks screeners are effective filters when you have a specific idea of the kinds of companies in which you are looking to invest. There are tens of thousands of stocks listed on world exchanges so it’s time-consuming to browse them manually. In this post I will show you have to built your own free stock screener using Python.

Continue reading “RSI stock screener”

Migration from Tkinter to Flask

The most popular library to create GUI in Python is Tkinter, which is a part of standard Python installation. Tkinter is a mature and stable tool, widely ported and relatively easy to learn. However, it is also quite old with many drawbacks, among them, it has a limited set of widgets. Although the simplistic model is easy to learn, Tkinter also becomes cumbersome with more complex interfaces. Above all, it does not support mobile and web application development.

Tkinter window
Tkinter window

Flask GUI
Flask GUI

Continue reading “Migration from Tkinter to Flask”

Tkinter list box with a search filter

Depending on the settings, a list box can be set to allow the user to select only one of the available options or multiple options. If the list is long what often happens if we work with a larger set of data, a filter used to select a few values is a handy addition. Using the filter, you can narrow down the list of values by typing a string of text in the search field above the list. The values that do not match the string are removed from the list. This particular filter needs pressing an ‘enter’ key to start processing the data. In Python Tkinter a list box is represented by Listbox widget.

Continue reading “Tkinter list box with a search filter”

GUI as a state machine

When interacting with GUI, a user should be able to supply only valid events at any given time. Thus if an application requires a user to perform event A before event B, the interface should ensure that event B is not possible until event A has been completed. It can be achieved by making certain GUI elements disappear or become disabled.

GUI states
GUI states

Continue reading “GUI as a state machine”

Parallel computation of prime numbers in Python

Engineers, scientists, and financial analysts frequently use optimization methods to solve computationally expensive problems such as simulation of complex systems, high-dimensional data analysis or data compression. Optimisation of algorithms can dramatically improve the performance of computation – even order or two orders of magnitude. One of the methods of optimisation is parallel computing. To derive the full gains of parallelization, it is important to choose an approach that is appropriate for the computation problem.

Continue reading “Parallel computation of prime numbers in Python”