Giter Site home page Giter Site logo

Asig metadata about pya HOT 4 OPEN

thomas-hermann avatar thomas-hermann commented on June 2, 2024
Asig metadata

from pya.

Comments (4)

thomas-hermann avatar thomas-hermann commented on June 2, 2024

Please take a look at the new branch feature-metadata, which implements a first version of a Metadata class.

  • I moved Asig.sr, Asig.cn, Asig.label to Metadata, (as this is meta data ;-)
  • but I added @properties, so that they can also be accessed and set as we are used to
  • the notebook Asig-metadata-test.ipynb shows how it works
    • the output is still a bit verbose yet...
  • a new Asig._copy_update() method facilitates a deep copy of an asig while excluding the deep copy of the contained sig in case a sig is updated.
    • This will facilitate lots of method returns
    • However, so far only few (fade_out, norm, plot, getitem) are rewritten, mainly for testing.

Pros:

  • metadata are flexible, extensible
  • better handling of revision, as list in metadata
  • simpler compilation of an Asig-to-return, no risk of forgetting to set values
  • context always copied on chained method invocations

Cons:

  • explicit access to new metadata (e.g. author, timestamp, etc.) takes
    asig.md.author (which is less readable than asig.author would be. However, I dislike the idea to clutter the Asig with lots of attributes.

Summary:

  • I am not 100% happy as of now... Ideas/ Suggestions welcome.

Next Steps:

  1. please could you take a look and comment?
  2. improve design,
  3. when we are satified, roll out to all methods

from pya.

aleneum avatar aleneum commented on June 2, 2024

Naming

just a thought. maybe info or meta is more comprehensive as a metadata name... asig.info.timestamp

Metadata object

Metadata could be moved to a separate file to declutter Asig.py. As it is a pure helper class I'd make it less verbose:

import time

class Metadata(dict):
    __getattr__ = dict.get
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__

    def __repr__(self):
        res = "Asig metadata:\n"
        for attr, value in self.items():  # sorted(self.items()) if keys should be in alphabetical order
            if value:
                if attr == 'timestamp':
                    value = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value))
                res += f"   {attr:>15} = {value}\n"
        return res

md = Metadata(foo="bar", bar=1, timestamp=time.time())
md.baz = 2.4
print(md)

In this less verbose form with less than 20 LOC it may also stay in Asig.py.

If possible do not name variables str, input or such alike. This will shadow and sometimes even overload builtins with nasty side effects.

from pya.

aleneum avatar aleneum commented on June 2, 2024

Three years later I'd probably use dataclasses for Metadata. Also we might want to introduce proper typing when we are at it. Python 2 support should not be an issue any longer (or is it)?

from pya.

thomas-hermann avatar thomas-hermann commented on June 2, 2024

wow. three years it is! tempus fugit.
Yes agreed. Data classes sounds very appropriate. Thanks for the suggestion.

from pya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.