Archive

Posts Tagged ‘ahradwani’

Python and Lindenmayer System – P2

November 3, 2019 1 comment


Learning : Lindenmayer System P2
Subject: Drawing with python using L-System

In the first part of Lindenmayer System L-System post (Click to Read) we had wrote two functions: one to generate the pattern based on the variables and roles, and one to draw lines and rotate based on the pattern we have.

In this part I will post images of what Art we can generate from L-System
the codes will be the L-system that generate the patterns, so the code will include: the Rules, Angle (Right, Left) Iteration and Starting Variable.


L-System: Koch Curve

L-System: Minkowski Sausage

L-System: … but here the Iteration is: 3

L-System: Again … but here the Iteration is: 3

L-System: Square Sierpinski

L-System: Sierpinski Arrowhead.

L-system: Dragon Curve

L-System: Koch Snowflake

L-System:

L-System:


The possibilities to generate the putters and therefore drawing the output is endless, any slightly changes in the iterations or rotation (+ -) angles will take all output to a new levels. In the coming post, I will use the L-system to generate fractal tree and see what we can get from there.



Follow me on Twitter..





My Fitbit Data

October 22, 2019 Leave a comment


Solving My Fitbit data Problem
Subject: VBA code to combine Fitbit excel files into one

I purchase a Fitbit Alta HR in 2017, and since then I wear it and never take it off unless for charging. Fitbit Alta HR is a very nice slim device, but unfortunately there was no way to upload my previous data from my old device to my Fitbit, this was not the only issue with Fitbit data, now; after three years still we can’t download Fitbit data in one file, if you want to do this (each time) you need to send a request to Fitbit team and they will prepare the file for you!! Instead, Fitbit site allow you to download your data as month by month, in my case I will have almost 32 files.

Solving the Problem: After downloading the excel files and look at them, I decide to write a code to help me combine all the current 32 files and any coming once into one data file. First I start thinking to use Python to do this task, but after second thought I will use the Excel file and VBA macro coding to do it.
Here in coming paragraph I will post about the general idea and some codes that i use.

General Idea: I will use same structure of Fitbit file and name it as “fitbit_All_data_ali”, in this file we will create new tab and name it Main. In the Main tab we will create several buttons using excel developer tools and will write the macro VBA code for each task we need to operate.

Tabs in our file: Main: Contain buttons and summary about my data.
Body, Food, Sleep, Activities and Food Log. Food Log tab will store the data such as calories, fibers, fat and so-on., all those tabs will be filled with a copied data from each Fitbit data file.

Here are some VBA codes that I use and what it’s purpose .

Code:
‘ Get current path.
the_path = Application.ActiveWorkbook.Path
The path on the current excel file.
Code:
the_All_Data_file = ThisWorkbook.Name
Get current excel file name
Code:
Workbooks.Open Filename:=thepath + my_source_Filename
Open a file
Code:
Windows(my_source_Filename).Activate
Sheets(“Foods”).Select
Range(“A2:B31”).Select
Selection.Copy
Goto fitbit file, goto food sheet, select the data copy it.
Code:
Application.CutCopyMode = False
Workbooks(my_source_Filename).Close SaveChanges:=False
Close an open excel file.
Code:
Range(“A3”).Select
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
To insert a black Row
Code:
sname = ActiveSheet.Name
Get current sheet name
Code:
Function go_next_sheet() As String

‘ This code will go to next sheet if there is one, if not will return ‘last’
go_next_sheet = “no”
Dim sht As Worksheet
Set sht = ActiveSheet

On Error Resume Next

If sht.Next.Visible xlSheetVisible Then
If Err 0 Then
go_next_sheet = “last”
End If

Set sht = sht.Next
End If

sht.Next.Activate
On Error Resume Next

End Function

if there is no more tabs or sheets, function will return “last”


Final Results: After i run the code, I have an Excel file contain all my Fitbit data in one place. Mission Accomplished



Follow me on Twitter..