Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • P PyMetric
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4
    • Issues 4
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • verktoy
  • PyMetric
  • Issues
  • #15
Closed
Open
Issue created Nov 07, 2019 by Morten Knutsen@mortenkContributor

speed to string only supports some specific speeds

Created by: runborg

https://github.com/Uninett/PyMetric/blob/b32bdde81308fdb0baf28c3a194ee58a1d2bd1ee/utils.py#L56-L72 cap2str does only support some specific speeds , comming with a 20Gbit/s link will result in an speed of "Unknown". this must be made more dynamic to allow for more custom speeds.

An example implementation:

def cap2str(capacity):
    if capacity < 1000:
        s, i = "K", float(capacity)
    elif capacity < 1000000:
        s, i = "M", round(float(capacity)/1000.0, 1)
    elif capacity < 1000000000:
        s, i = "G", round(float(capacity)/1000000.0, 1)
    elif capacity < 1000000000000:
        s, i = "T", round(float(capacity)/1000000000.0,1)

    if i % 1 == 0:
        return "{:0.0f}{}bit/s".format(i, s)
    else:
        return "{:0.1f}{}bit/s".format(i, s)

This will produce:

       600  :  600Kbit/s
      1500  :  1.5Mbit/s
      1984  :  2Mbit/s
     34000  :  34Mbit/s
     34010  :  34Mbit/s
    100000  :  100Mbit/s
    155000  :  155Mbit/s
   1000000  :  1Gbit/s
   2488000  :  2.5Gbit/s
   2500000  :  2.5Gbit/s
   5000000  :  5Gbit/s
  10000000  :  10Gbit/s
  20000000  :  20Gbit/s
  25000000  :  25Gbit/s
  40000000  :  40Gbit/s
  50000000  :  50Gbit/s
 100000000  :  100Gbit/s
 200000000  :  200Gbit/s
 400000000  :  400Gbit/s
 800000000  :  800Gbit/s
1000000000  :  1Tbit/s
1200000000  :  1.2Tbit/s
Assignee
Assign to
Time tracking