dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help with scanning data from multiple text files

Hybrid View

  1. #1
    Join Date
    Nov 2015
    Posts
    1

    Help with scanning data from multiple text files

    Hi,

    I have multiple text files that contains information about different programming languages popularity in different countries based off of google searches. I have one text file for each year from 2004 to 2015. I also have a text file that breaks this down into each week (called iot.txt) but this file does not include the country.

    Example data from 2004.txt:

    Code:
    Region  java    c++ c#  python  JavaScript
    
    Argentina   13  14  10  0   17
    
    Australia   22  20  22  64  26
    
    Austria 23  21  19  31  21
    
    Belgium 20  14  17  34  25
    
    Bolivia 25  0   0   0   0
    etc

    example from iot.txt:

    Code:
    Week    java    c++ c#  python  JavaScript
    
    2004-01-04 - 2004-01-10 88  23  12  8   34
    
    2004-01-11 - 2004-01-17 88  25  12  8   36
    
    2004-01-18 - 2004-01-24 91  24  12  8   36
    
    2004-01-25 - 2004-01-31 88  26  11  7   36
    
    2004-02-01 - 2004-02-07 93  26  12  7   37
    My problem is that i am trying to write code that will output the number of countries that have exhibited 0 interest in python.

    This is my current code that I use to read the text files. But I'm not sure of the best way to tell the number of regions that have 0 interest in python across all the years 2004-2015. At first I thought the best way would be to create a list from all the text files not including iot.txt and then search that for any entries that have 0 interest in python but I have no idea how to do that.

    Can anyone suggest a way to do this?

    Code:
    import java.io.BufferedReader;
    import java.io.FileReader;
    
    import java.util.*;
    
    public class Starter{
    
        public static void main(String[] args) throws Exception {
            BufferedReader fh =
                    new BufferedReader(new FileReader("iot.txt"));
            //First line contains the language names
            String s = fh.readLine(); 
            List<String> langs =
                    new ArrayList<>(Arrays.asList(s.split("\t")));
            langs.remove(0);    //Throw away the first word - "week"
            Map<String,HashMap<String,Integer>> iot = new TreeMap<>();
            while ((s=fh.readLine())!=null)
            {
                String [] wrds = s.split("\t");
                HashMap<String,Integer> interest = new HashMap<>();
                for(int i=0;i<langs.size();i++)
                    interest.put(langs.get(i), Integer.parseInt(wrds[i+1]));
                iot.put(wrds[0], interest);
            }
            fh.close();
            HashMap<Integer,HashMap<String,HashMap<String,Integer>>>
                regionsByYear = new HashMap<>();
            for (int i=2004;i<2016;i++)
            {
                BufferedReader fh1 =
                        new BufferedReader(new FileReader(i+".txt"));
                String s1 = fh1.readLine(); //Throw away the first line
                HashMap<String,HashMap<String,Integer>> year = new HashMap<>();
                while ((s1=fh1.readLine())!=null)
                {
                    String [] wrds = s1.split("\t");
                    HashMap<String,Integer>langMap = new HashMap<>();
                    for(int j=1;j<wrds.length;j++){
                        langMap.put(langs.get(j-1), Integer.parseInt(wrds[j]));
                    }
                    year.put(wrds[0],langMap);
                }
                regionsByYear.put(i,year);
                fh1.close();
            }
        }
    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    Re: Help with scanning data from multiple text files

    search that for any entries that have 0 interest in python
    You should create a class to hold the data from a line in a file. Read the lines of the file, create instances of the class and then store those instances in a collection like an ArrayList. After all lines have been read, you can search the collection for the desired selection criteria: 0 interest in python
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)