How can I get the number of all bitcoins in the network? - api

I am trying to query the bitcoin daemon in order to find out what's the total amount of bitcoins mined/produced so far in order to calculate the market capitalization. However, I can't seem to find any command that does that.
I've checked the following link to no avail:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

You can find that information from the number of blocks. 50 BTC per block were created for the first 210 000 blocks, then 25 BTC per block for the next 210 000 blocks, etc.
If I take, say:
http://bitcoincharts.com/
as I write this SO answer I can read:
Blocks 279383
Total BTC 12.235M
Starting from 279 383 blocks you can find:
210 000 * 50 = 10 500 000
(279 383 - 210 000) * 25 = 1 734 575
10 5000 + 1 734 575 = 12 234 575
12 234 575 which that site rounded up as "12.235M"
This is not 100% correct as the first 50 bitcoins were not usable etc. moreover it's a fact that quite a lot of the early bitcoins mined are lost forever.
But that approximation should be "close enough" and seems to be what most sites are using.

Related

Plotting Webscraped data onto matplotlib

I recently managed to collect tabular data from a PDF file using camelot in python. By collect I mean print it out on the terminal, Now i would like to find a way to automate the results into a bar graph diagram on matplotlib. how would i do that? Here's my code for extracting the tabular data from the pdf:
import camelot
tables = camelot.read_pdf("data_table.pdf", pages='2')
print(tables[0].df)
Here's an image of the table
enter image description here
Which then prints out a large table in my terminal:
0 1 2 3 4
0 Country \nCase definition \nCumulative cases \...
1 Guinea Confirmed 2727 156 1683
2 Probable 374 * 374
3 Suspected 7 * ‡
4 Total 3108 156 2057
5 Liberia** Confirmed 3149 11 ‡
6 Probable 1876 * ‡
7 Suspected 3982 * ‡
8 Total 9007 11 3900
9 Sierra Leone Confirmed 8212 230 3042
10 Probable 287 * 208
11 Suspected 2604 * 158
12 Total 11103 230 3408
13 Total 23 218 397 9365
I do have a bit of experience with matplotlib and i know how to plot data manually but not automatically from the pdf. This would save me some time since I'm trying to automate the whole process.

SQL code guidance

I've recently had to start using SQL, and am struggling a little with how to code some more advanced capabilities etc, so was hoping for some guidance.
I have one database that contains high level data split by geography, NAICS industry and size of company, with field names such as:
CBSACODE VERTICAL COMPANYSIZE DEVICES
01010 Agriculture 1-10 100
01010 Education 20-99 50
01010 Healthcare 200-499 250
01010 Manufacturing 100-199 150
01010 Manufacturing 1-10 80
78910 Agriculture 1-10 25
78910 Government 500+ 400
78910 Agriculture 11-19 60
78910 Finance 100-199 310
78910 Retail 20-99 200
I have a second database which is at a customer level but has some overlapping fields
CUSTOMER NAME VERTICAL COMPANYSIZE ZIPCODE CBSACODE
Customer A Agriculture 1-10 12345 78910
Customer B Manufacturing 100-199 54321 01010
What I am trying to do is to display the list of customers, and then display the sum of 'Number of devices' based on matching the CBSA Code, Vertical Industry and Company Size for each customer against the first database.
CUSTOMER NAME CBSADEVICES CBSA+VERTICALDEVICES COSIZEDEVICES
Customer A 995 85 25
Customer B 630 230 150
I started trying to write a query using SUM and CASE WHEN etc but quickly got overwhelmed.
I'm using MS SQL Server 2016 (Express).
Any guidance would be greatly appreciated.....I've read through a number of various threads, but have yet to get my head around it sadly.

SQL: How to remove & update records in a table, sync'ing with a (Q)List data in order to decrease the burden on database/table?

I am using Qt and MS-Sql Server on Windows7 OS.
What I have is an MS-SQL database that I use to store data/info coming from equipment that is mounted in some vehicles.
There is a table in the database named TransactionFilesInfo - a table used to store information about transaction files from the equipment, when they connect to the TCP-server.
We are using this table as we are requested to avoid duplicate files. It happens (sometimes) when the remote equipment does NOT delete the transaction files after they are sent to the server. Hence, I use the info from the table to check [size and CRC] to avoid downloading duplicates.
Some sample data for TransactionFilesInfo table looks like this:
[TransactionFilesInfo]:
DeviceID FileNo FileSequence FileSize FileCRC RecordTimeStamp
10203 2 33 230 55384 2015-11-26 14:54:15
10203 7 33 624 55391 2015-11-26 14:54:15
10203 2 34 146 21505 2015-11-26 14:54:16
10203 7 34 312 35269 2015-11-26 14:54:16
10203 2 35 206 23022 2015-11-26 15:33:22
10203 7 35 208 11091 2015-11-26 15:33:22
10203 2 36 134 34918 2015-11-26 15:55:44
10203 7 36 104 63865 2015-11-26 15:55:44
10203 2 37 140 35466 2015-11-26 16:20:38
10203 7 37 208 62907 2015-11-26 16:20:38
10203 2 38 134 17706 2015-11-26 16:38:33
10203 7 38 104 42358 2015-11-26 16:38:33
11511 2 21 194 29913 2015-12-02 16:22:59
11511 7 21 114 30038 2015-12-02 16:22:59
On the other hand, every time a device connects to the server, it first sends a list of file information. The Qt application takes care of that.
The list contains elements like this:
struct FileInfo
{
unsigned short FileNumber;
unsigned short FileSequence;
unsigned short FileCRC;
unsigned long FileSize;
};
So, as an example (inspired by the table above) the connected device (DeviceID=10203) may say that it has the following files:
QList<FileInfo> filesList;
// here is the log4qt output...
filesList[0] --> FileNo=2 FileSeq=33 FileSize=230 and FileCRC=55384
filesList[1] --> FileNo=2 FileSeq=34 FileSize=146 and FileCRC=21505
filesList[2] --> FileNo=7 FileSeq=33 FileSize=624 and FileCRC=55391
filesList[3] --> FileNo=7 FileSeq=34 FileSize=312 and FileCRC=35269 ...
Well, what I need is a method to remove/delete, for a given DeviceID, all the records in the TransactionFilesInfo table, records that are NOT in the list sent by the remote device. Hence, I will be able to decrease the burden (size) on the database table.
Remark: For the moment I just delete (#midnight) all the records that are older than let's say 10 days, based on RecordTimeStamp field. So, the size of the table doesn't increase over an alarming level :)
Finally, to clarify it a little bit: I would mainly need help with SQL. Yet, I would not refuse any idea on how to do some related things/tricks on the Qt side ;)
The SQL to delete those records might look something like this:
DELETE FROM [SAMPLE DATA]
WHERE DeviceID = 10203
and 'File' + CONVERT(varchar(11),FileNo) + '_' +
RIGHT('000' + CONVERT(varchar(11),FileSequence),3)
NOT IN ('File2_033','File2_034','File7_033','File7_034',...)
If you wanted to delete all of them for a device, you could drop the code that looks at the FileNo and FileSequence so it is simply:
DELETE FROM [SAMPLE DATA]
WHERE DeviceID = 10203

MS SQL Store Procedure Optimizing

I have attached my query result. How can I optimize this sp? Also do I need to optimize? I can get the result in 0.2 or in some case more.
Client Execution Time 18:18:18 18:18:08 18:17:49 18:17:24 18:13:18
Query Profile Statistics
Number of INSERT, DELETE and UPDATE statements 281 281 281 50 0 178.6000
Rows affected by INSERT, DELETE, or UPDATE statements 235 235 235 44 0 149.8000
Number of SELECT statements 4870 4870 4870 741 13 3072.8000
Rows returned by SELECT statements 3653 3653 3653 598 37 2318.8000
Number of transactions 281 281 281 50 0 178.6000
Network Statistics
Number of server roundtrips 1 1 1 3 3 1.8000
TDS packets sent from client 1 1 1 3 3 1.8000
TDS packets received from server 119 110 90 898 78 259.0000
Bytes sent from client 138 138 138 284 288 197.2000
Bytes received from server 327491 327491 327491 2861601 197860 808386.8000
Time Statistics
Client processing time 2755 3793 2364 908 332 2030.4000
Total execution time 3225 4294 2825 2095 1375 2762.8000
Wait time on server replies 470 501 461 1187 1043 732.4000
There's a number of options you can look at:
1.SQL Merge
SQL Merge can be used to perform Inserts, Updates and Deletes in a single statement.
http://technet.microsoft.com/en-us/library/bb510625.aspx
http://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/
2.Output Clause
The SQL output clause can be used to return any value from ‘inserted’ and ‘deleted’ (New value and Old value) tables when doing an insert or update.
http://msdn.microsoft.com/en-us/library/ms177564(v=sql.90).aspx

How to read data on a specific row from excel by asking the name of that row?

I have the following excel file:
W1000x554 1032 408 52.1 29.5 70700 12300
W1000x539 1030 407 51.1 28.4 68700 12000
W1000x483 1020 404 46 25.4 61500 10700
W1000x443 1012 402 41.9 23.6 56400 9670
W1000x412 1008 402 40 21.1 52500 9100
W1000x371 1000 400 36.1 19 47300 8140
W1000x321 990 400 31 16.5 40900 6960
W1000x296 982 400 27.1 16.5 37800 6200
W1000x584 1056 314 64 36.1 74500 12500
I want to define a function that can ask the user for one of the first column's names and then read all the relevant data of that row later.
For example if the user defines W1000x412 then read : 1008 402 40 21.1 52500 9100.
Any ideas?
I suspect what #Marc means is that a formula such as in J2 below (copied across and down as necessary) will 'pick out' the values you want. It is not clear to me from your question whether these should be kept separate (as in Row2 of example) or strung together (CONCATENATE [&] as in J7 of example, where these are space [" "] delimited):
I am also not entirely sure about your 'define a function' but have assumed you do not require a UDF.
I have used Row1 to provide the offset for VLOOKUP, to save adjusting manually the formula for each column.
ColumnI is the expected user input, that might be best by selection from a Data Validation List with Source $A$2:$A$10.