IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Tableau 2D et segmentation


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    amateur
    Inscrit en
    Octobre 2007
    Messages
    731
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : amateur

    Informations forums :
    Inscription : Octobre 2007
    Messages : 731
    Par défaut Tableau 2D et segmentation
    Hello,

    J'ai surligné en rouge dans le code les lignes qui me provoquent les erreurs rencontrées.
    Le problème vient visiblement de mon tableau 2D déclaré ainsi :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $matrix = New-Object 'object[,]' 100000,2;
    Je n'arrive pas à piger ce que je rate.

    Erreur 1 ( première ligne surlignée en rouge )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    L'index se trouve en dehors des limites du tableau.
    Au caractère script.ps1:59 : 9
    +         $matrix[1, 2] += [decimal]$balance_confirmed;
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], IndexOutOfRangeException
        + FullyQualifiedErrorId : System.IndexOutOfRangeException
    Erreur 2 ( seconde ligne surlignée en vert ), à priori logique et conséquente à la première.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Échec lors de l’appel de la méthode, car [System.Object[]] ne contient pas de méthode nommée «*op_Subtraction*».
    Au caractère script.ps1:65 : 14
    + ...        if ( ( $balance_confirmed -gt $matrix[$index-1,2]) -And ( $ind ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation : (op_Subtraction:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
    Voici le code complet avec les lignes en défaut.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    #FUNCTIONS
    Function Get-EpochTime()
    {
        $D = ("01/01/1970" -as [DateTime])
        [int]$int_nonce = ((New-TimeSpan -Start $D -End ([DateTime]::UtcNow)).TotalSeconds -as [string])
        [string]$str_nonce = ($int_nonce -as [string])
        return $str_nonce
    }
    
    
    #MAIN
    cls;
    #Url of json api requests (wallet whitout "0x")
    $nanopoolApi_ETH_req_00 = "whatever";
    $nanopoolApi_ETH_req_01 = "https://api.nanopool.org/v1/eth/prices"
    $cryptocoApi_ETH_req_00 = "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=EUR";
    
    #Initializing DATA
    
    $balance_total = 0;
    $file = New-Item -type file "log.txt" -Force
    
    #When balanced_confirmed is incremented, we want to stock both epoch time and confirmed balance in order to compute mining speed.
    $index    = 1; #Represents the number of confirmed balance's increments over the script running's time
    $field_id = 1; #Represents the id of the fields (1=epoch time)(2=confirmed balance) for each increments of confirmed_balance.
    $matrix = New-Object 'object[,]' 100000,2; 
    
    $loop = 1
    #Starting the loop
    Do { 
        $t = Get-EpochTime;
    
        #Converting eth.nanopool API requests to json Objects
        $json_nanopoolApi_ETH_req_00 = (Invoke-WebRequest $nanopoolApi_ETH_req_00).content | ConvertFrom-Json ;
        $json_nanopoolApi_ETH_req_01 = (Invoke-WebRequest $nanopoolApi_ETH_req_01).content | ConvertFrom-Json ;
        #Converting other API requests to json Objects
        $json_cryptocoApi_ETH_req_00 = (Invoke-WebRequest $cryptocoApi_ETH_req_00).content | ConvertFrom-Json ; 
      
        #Getting appropriate DATA
        $balance_unconfirmed = [decimal]$json_nanopoolApi_ETH_req_00.data.unconfirmed_balance;
        $balance_confirmed   = [decimal]$json_nanopoolApi_ETH_req_00.data.balance;
        $hashrate_current    = [decimal]$json_nanopoolApi_ETH_req_00.data.hashrate;
        $hashrate_avg_h01    = [decimal]$json_nanopoolApi_ETH_req_00.data.avghashrate.h1;
        $hashrate_avg_h03    = [decimal]$json_nanopoolApi_ETH_req_00.data.avghashrate.h3;
        $hashrate_avg_h06    = [decimal]$json_nanopoolApi_ETH_req_00.data.avghashrate.h6;
        $hashrate_avg_h12    = [decimal]$json_nanopoolApi_ETH_req_00.data.avghashrate.h12;
        $hashrate_avg_h24    = [decimal]$json_nanopoolApi_ETH_req_00.data.avghashrate.h24;
        
        $eth_to_eur_nanopool = [decimal]$json_nanopoolApi_ETH_req_01.data.price_eur;
        $eth_to_eur_cryptoco = [decimal]$json_cryptocoApi_ETH_req_00.eur;
    
        $balance_total = $balance_confirmed + $balance_unconfirmed 
        $eth_total_eur = $eth_to_eur_nanopool*$balance_total
            
        #Processing DATA
        if ( $index -eq 1 )
        {
            $matrix[1, 1] += t;
            $matrix[1, 2] += $balance_confirmed;
            $index++;
        }
        else
        {
    
            if ( ( $balance_confirmed -gt $matrix[$index-1,2]) -And ( $index -ge 3 ) )
            {
                #Storing the time and balance_confirmed
                $matrix[$index, 1] += $t; 
                $matrix[$index, 2] += $balance_confirmed;
                
                #Delta of time and balance_confirmed between 2 consecutive increments of balance_confirmed
                $balance_ti = $matrix[$index,1] - $matrix[1,1];
                $ti         = $matrix[$index,2] - $matrix[1,2];
                
                #Statistics ETH/period
                $eth_per_sec = $balance_ti/$ti
                $eth_per_min = $eth_per_sec*60
                $eth_per_hou = $eth_per_min*60
                $eth_per_day = $eth_per_hou*24
                $eth_per_wee = $eth_per_day*7
                $eth_per_mon = $eth_per_day*30.42
                $eth_per_yea = $eth_per_day*365
                
                #Statistics EUR/period
                $eur_per_sec = $eth_per_sec*$eth_to_eur_nanopool
                $eur_per_min = $eth_per_min*$eth_to_eur_nanopool
                $eur_per_hou = $eth_per_hou*$eth_to_eur_nanopool
                $eur_per_day = $eth_per_day*$eth_to_eur_nanopool
                $eur_per_wee = $eth_per_wee*$eth_to_eur_nanopool
                $eur_per_mon = $eth_per_mon*$eth_to_eur_nanopool
                $eur_per_yea = $eth_per_yea*$eth_to_eur_nanopool
    
                $index++;
            }
        }
    
        #Formating output DATA 
        cls;
        "";
        "LOOP N°" + $loop
        "------------ RIG ETH ------------" 
        "" 
        "< HASHRATE STATS >" 
        "" 
        'Hashrate : Current = ' + $hashrate_current + ' Mh/s'
        'Hashrate : H01     = ' + $hashrate_avg_h01 + ' Mh/s' 
        'Hashrate : H03     = ' + $hashrate_avg_h03 + ' Mh/s' 
        'Hashrate : H06     = ' + $hashrate_avg_h06 + ' Mh/s' 
        'Hashrate : H12     = ' + $hashrate_avg_h12 + ' Mh/s' 
        'Hashrate : H24     = ' + $hashrate_avg_h24 + ' Mh/s' 
        "" 
        "< ETHERUM MINER STATS >" 
        "" 
        'Balance : unconfirmed = ' + $balance_unconfirmed + ' ETH'
        'Balance : confirmed   = ' + $balance_confirmed + ' ETH'
        'Balance : total      = ' +$balance_total + ' ETH'
        ""
        '1 ETH     = ' + $eth_to_eur_nanopool + ' € from nanopool' 
        '1 ETH     = ' + $eth_to_eur_cryptoco + ' € from cryptocompare' 
        'Total EUR = ' + $eth_total_eur + ' €' 
        ""
        
        "< ETHERUM MINING STATS >"
        ""
        if ( $index -ge 3 )
        {
            'ETH per sec ' + $eth_per_sec 
            'ETH per min ' + $eth_per_min
            'ETH per hou ' + $eth_per_hou
            'ETH per day ' + $eth_per_day
            'ETH per wee ' + $eth_per_wee
            'ETH per mon ' + $eth_per_mon
            'ETH per yea ' + $eth_per_yea
            ""
            'EUR per sec ' + $eur_per_sec
            'EUR per min ' + $eur_per_min
            'EUR per hou ' + $eur_per_hou
            'EUR per day ' + $eur_per_day
            'EUR per wee ' + $eur_per_wee
            'EUR per mon ' + $eur_per_mon
            'EUR per yea ' + $eur_per_yea
        }
        else 
        {
            "Ethereum mining stats cannot be displayed at the moment"
            "It will take at least 30 minutes to get the first values"
            "Values will become more and more accurate with time"
            "6 hours required to display the first accurate values"
        }
    
        $loop++;
        $te = Get-EpochTime;
        $te = $te - $t;
        $T = 10 - $te;
        timeout -t $T
    } 
    While (1)
    Merci d'avance. Cordialement.

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Billets dans le blog
    1
    Par défaut
    Salut,
    l'indice débute à Zéro :
    Et ici utilise des parenthèses :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    10 -gt $matrix[($index-1),1]

Discussions similaires

  1. Réponses: 7
    Dernier message: 20/01/2010, 11h23
  2. Erreur de segmentation avec un tableau 2D
    Par yeahahoohoo dans le forum C++
    Réponses: 4
    Dernier message: 18/03/2009, 22h53
  3. Réponses: 5
    Dernier message: 04/11/2007, 13h39
  4. Réponses: 14
    Dernier message: 26/11/2006, 13h14
  5. Réponses: 23
    Dernier message: 08/01/2006, 22h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo