Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:51:49+00:00 2026-06-01T20:51:49+00:00

I am recording the input from a serial connection. At the moment, I have

  • 0

I am recording the input from a serial connection.

At the moment, I have been using a basic class that the input is run through updating self.min & self.max

But perhaps there is a more efficient way to do this?

perhaps a deque? would this have efficiency benefits?
perhaps a class is not needed?


An example of one that I have used:

class RangeFinder(object):

    def __init__(self, _mem=3) :
        self._mem = deque(maxlen=_mem)
        self.absmax = -10**10
        self.absmin = 10**10
        self.relmax = None
        self.relmin = None

    def read(self, _data) :
        if _data != None:
            self._mem.append(_data)
            if len(self._mem) == self._mem.maxlen :       
                self.relmax = max(self._mem)
                self.absmax = max(self.absmax, self.relmax)      
                self.relmin = min(self._mem)    
                self.absmin = min(self.absmin, self.relmin) 

another idea:

class MinMax(deque):

    def __init__(self):
        deque.__init__(self, [ 10**10, -10**10 ], maxlen=2)

    def read(self, _data):
        if _data < self[0]:
            self.popleft()
            self.appendleft(_data)
        if _data > self[1]:
            self.pop()
            self.append(_data)

input is a string that is converted to an int. I have only recently begun using the serial connection as a generator so there are some discrepancies.

The min and max are then used to calculate the intensity of a lazer for reading binary data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:51:50+00:00Added an answer on June 1, 2026 at 8:51 pm

    I would go for a bisection here to maintain the order when you input data. So that the lookup for the min/max will be O(1) and the load would go on the insertion (O(nlogn)). Also I don’t think you need a class here, you can safely implement only functions (if the problem is as you described it).

    >>> import random
    >>> import bisect
    >>> data = []
    >>> input_data = random.sample(range(1000),100) 
    >>> #Substitute this with your serial input data
    >>> for i in input_data:
    ...     bisect.insort(data, i)
    >>> min = data[0]
    >>> max = data[-1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one record audio using iOS? Not the input recording from the microphone,
I have a program that records audio from firewire device (FA-66) with Jack connection.
I'm already recording from my iSight from a python script using the pyobjc bridge
I have to send the audio data in byte array obtain by recording from
I have an OpenGL view of which I am recording a video using what
I am using tinyxml to save input from a text ctrl. The user can
We have an application that logs to files currently using streamwriter. As we are
I have recently had some input from a colleague regarding committing in a stored
From some reading and input from a couple of seasoned developers, it appears that
I have an application that processes data stored in a number of files from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.