Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pteretis
Nov 4, 2011

Naffer posted:

Humble Request
Problem:
I have a scientific instrument that collects data on samples to individual folders. I would like to be able to go back and calculate how much instrument time was used on each sample.

Here's what I got with a quick go at it in Python. I'm not 100% on what your preferred formatting is but let me know if you want any changes.

If anyone wants to point out things that can be improved then I am open to critique, I'm not exactly experienced.

Request Fill
Source Code:
code:
import os
import time

with open("output.txt", "w") as out:
    print("Instrument time per sample", file = out)

dirs = next(os.walk("."))[1]
for user in dirs:
    samples = next(os.walk(user))[1]
    for sample in samples:
        path = user + "/" + sample + "/frames"
        files = next(os.walk(path))[2]
        new = 0
        old = 0
        for file in files:
            fileTime = os.path.getctime(path + "/" + file)
            if old == 0:
                old = fileTime
            if fileTime < old:
                old = fileTime
            if fileTime > new:
                new = fileTime
        date = time.strftime("%Y-%m-%d", time.localtime(old))
        diff = round(new - old)
        minute, second = divmod(diff, 60)
        hour, minute = divmod(minute, 60)
        with open("output.txt", "a") as out:      
            print("%s\t%s\t[%s]\t%02d:%02d:%02d" %
                (user, sample, date, hour, minute, second), file = out)
Features and Usage:
Just run it in the parent of the User directory and it will generate a text file with all of the data.

Adbot
ADBOT LOVES YOU

Pteretis
Nov 4, 2011

Sorry about that, I should have specified that it's for Python 3, which doesn't have compatibility with Python 2.

Pteretis
Nov 4, 2011

Naffer posted:

Awesome. I added a couple of features.
1) now it only uses files that match the sample name for the calculation.
2) Added error handling for when it encounters subfolders that don't have the expected path (would throw up if there was a missing frames folder)

Cool, glad to hear it's working. The additions look good :).

Pteretis
Nov 4, 2011

Request Fill
Name:Video Snapshot
Download link: https://www.mediafire.com/file/w3qv0zp3s6q9ndr/VideoSnapShot.exe
Source Code: https://github.com/Ptarmigans/VideoSnapshot
Features and Usage: Takes snapshots of videos at the interval specified in the time box. Files can either be dragged into the window or added using the + button.
Screenshot:


Requires .net 4.5 and having ffmpeg set up on your PATH.
Disclaimer. I've never used C# before, I've never made a GUI before, this hasn't been thoroughly tested, I'm a shameful programmer and the source will probably make people upset.
That said, let me know if there are any problems.

Pteretis
Nov 4, 2011

nexxai posted:

If you look at the "Time between captures", it's like it's reading it as a clock time, rather than an interval, to the point where if you replace the "12" with "00", it goes back to 12 automatically. What you're seeing actually does function as a 5 minute interval, so it's not like it's broken, it's just kind of funny to look at.

Oh, lol. I used the time/date picker to avoid having to do any data validation, I guess that's what I get. This should fix it http://www.mediafire.com/file/adlgkb55xmae4xm/VideoSnapShot.exe, let me know if it doesn't. Glad it's working other than that.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply